﻿
using JinYuan.Helper;
using JinYuan.MES.Enums;
using JinYuan.Models;
using JinYuan.VirtualDataLibrary;
using Language;
using PLCCommunication;
using PLCCommunication.Common;
using PLCCommunication.Common.DataConvert;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
//using JinYuan.DataConvertLib;

namespace JinYuan.ControlCenters
{
    public partial class ControlCenter
    {
        public object FileLock = new object();//文件锁
        //static MqttService mqttService = new MqttService(new MqttService.MqttConfig
        //{
        //    ServerAddress = "10.22.161.1",
        //    ServerPort = 2883,
        //    ClientId = "601PWM01",
        //    TopicInOut = "EVE/60J/TrackInOut/601PWM01",
        //    TopicForecast = "EVE/60J/EQP/601PWM01"
        //});


        #region 上料工位(数据处理)
        /// <summary>
        /// 上料工位A
        /// </summary>
        //int JXCount = 0;
        //上料解析
        private async Task FeedingStationA(JYResult<byte[]> bArrays, object plcModel)
        {
            PlcGroup pf = plcModel as PlcGroup;
            var sw = new Stopwatch();
            if (bArrays.IsSuccess && bArrays.Content != null)
            {
                try
                {
                    sw.Restart();
                    #region 数据初始化
                    //解析数据
                    List<AGearEntity> list = new List<AGearEntity>();//实体
                    List<short> listRes = GetList<short>(3, 2);//默认为1，良品
                    List<bool> listMark = GetList<bool>(3, false);//有料标志
                    List<string> listCode = GetList<string>(3, "");//电芯码
                    List<string> listRemark = GetList<string>(3, "");//备注
                    List<string> listFlag = GetList<string>(3, "0");//是否上传标志
                    List<string> listResult = GetList<string>(3, "OK");//结果
                    List<string> listMesage = GetList<string>(3, "");//mesMesage
                    List<MesResType> listMesResType = GetList<MesResType>(3, MesResType.B);//mesType
                    #endregion

                    // 从D2021开始
                    #region 数据解析
                    byte[] bytes = bArrays.Content.ByteReverse();//高低位转换

                    //有料标志
                    for (int i = 0; i < listMark.Count; i++)
                    {
                        listMark[i] = true;//ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2)) == 1 ? true : false;// 从D2021开始
                        if (listMark[i])
                        {
                            #region 数据读取
                            //条码长度
                           // ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (20 * 2));// 从D2041开始
                            listCode[i] = StringLib.GetStringFromByteArrayByEncoding(bArrays.Content, i * 2 * 20, 20 * 2, System.Text.Encoding.ASCII).// 从D2100开始
                                 Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim();
                            if (String.IsNullOrEmpty(listCode[i]) || listCode[i].Trim() == "ERROR")
                            {
                                listCode[i] = "ERROR";
                                //listRes[i] = 2;//条码NG
                            }
                            #endregion

                            #region 数据保存
                            AGearEntity m = new AGearEntity();
                            m.BarCode = listCode[i];
                            m.ChannelNo = (i + 1).ToString();
                            m.TestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                            list.Add(m);
                            #endregion
                        }
                        else
                        {
                            CommonMethods.AddDataMonitorLog(0, "进站上料工位A有料标志为0".Translated() + "通道号".Translated() + $"：{i}");
                        }
                    }
                    #endregion

                    #region 上传MES
                    //上传MES
                    if (list.Count > 0)
                    {
                        if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
                        {
                            //var codeList = list.Select(m => m.BarCode).ToList();
                            //var (success1, mesage1, mesResType1) = await CommonMethods.hbgMes.ManyCellInStationAsync(CommonMethods.mesConfig.ProductInStation, CommonMethods.mesConfig.siteCode, CommonMethods.mesConfig.lineCode,
                            //                CommonMethods.mesConfig.equipNum, CommonMethods.mesConfig.MaterialCode, CommonMethods.mesConfig.mesUserName, codeList);
                            var allMesMessages = new List<string>();
                            var allMesResTypes = new List<MesResType>();
                            var allFlags = new List<string>();
                            foreach (var item in list)
                            {
                                // 每次只上传一个条码（封装为List）
                                var singleCodeList = new List<string> { item.BarCode };

                                var (success1, mesage1, mesResType1) = await CommonMethods.hbgMes.ManyCellInStationAsync(
                                    CommonMethods.mesConfig.ProductInStation,
                                    CommonMethods.mesConfig.siteCode,
                                    CommonMethods.mesConfig.lineCode,
                                    CommonMethods.mesConfig.equipNum,
                                    CommonMethods.mesConfig.MaterialCode,
                                    CommonMethods.mesConfig.mesUserName,
                                    singleCodeList);  // 单条码列表
                                if (success1)
                                {
                                    // 收集结果而不是覆盖
                                    allMesMessages.AddRange(mesage1);
                                    allMesResTypes.AddRange(mesResType1);
                                    allFlags.Add("1");
                                }
                                else
                                {
                                    // 收集失败结果
                                    allMesMessages.AddRange(mesage1);
                                    allMesResTypes.AddRange(mesResType1);
                                    allFlags.Add("2");
                                    // 记录失败状态
                                    listRes = GetList<short>(3, 3);
                                    listRemark = GetList<string>(3, "");
                                    if (mesage1.Count > 0 && mesage1[0].Contains("一个或多个错误"))
                                    {
                                        CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short); // 反馈PLC结果
                                    }
                                }
                            }
                            // 将收集的结果赋给主列表
                            listMesage = allMesMessages;
                            listMesResType = allMesResTypes;
                            listFlag = allFlags;
                        }
                        else
                        {
                            listRes = GetList<short>(3, 3);
                            listRemark = GetList<string>(3, "MES断连".Translated());
                            listFlag = GetList<string>(3, "2");

                            CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short);//反馈MES结果
                        }
                    }
                    #endregion

                    #region 数据组合
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (String.IsNullOrEmpty(list[i].BarCode) || list[i].BarCode.Trim() == "ERROR" || !IsAlphaNumeric(list[i].BarCode))
                        {
                            listRes[i] = 2;
                            listResult[i] = "NG";
                            listRemark[i] = "电芯码不良".Translated();
                        }
                        else
                        {
                            int codeIndex = i;//listCode.Count - i - 1;
                            listResult[i] = "OK,";

                            switch (listMesResType[codeIndex])
                            {
                                case MesResType.A:// 停线，设备报警停机
                                    listResult[i] += "MES NG";
                                    listRemark[i] += listMesage[codeIndex];
                                    listRes[i] = 3;//10
                                    break;
                                case MesResType.B:// 排出
                                    listResult[i] += "MES NG";
                                    listRemark[i] += listMesage[codeIndex];
                                    listRes[i] = 3;//2
                                    break;
                                case MesResType.C:// 警示
                                case MesResType.D:// 条码上传OK
                                    listResult[i] += "MES OK";//MES认为是可以当成良品流下去的
                                    listRemark[i] += listMesage[codeIndex];
                                    listRes[i] = 1;
                                    break;
                                default:
                                    listResult[i] += "MES NG";
                                    listRemark[i] += listMesage[codeIndex];
                                    listRes[i] = 3;//2
                                    break;
                            }
                        }

                        list[i].Result = listResult[i].TrimStart(',').TrimEnd(',');
                        list[i].Remark = listRemark[i].TrimStart(',').TrimEnd(',');
                        list[i].Flag = listFlag[i];

                    }
                    #endregion

                    #region 旧
                    //for (int i = 0; i < listCode.Count; i++)
                    //{
                    //    if (listMark[i])
                    //    {
                    //        AGearEntity m = new AGearEntity();
                    //        //string str222 = "";
                    //        m.ChannelNo = (i + 1).ToString();
                    //        m.TestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    //        m.BarCode = listCode[i];
                    //        m.Flag = "0";
                    //        if (String.IsNullOrEmpty(m.BarCode) || m.BarCode.Trim() == "ERROR" || !IsAlphaNumeric(m.BarCode))
                    //        {
                    //            //m.RFID = "NG";
                    //            //m.BarCode = "NG";
                    //            m.Result = "NG";
                    //            m.Remark = "电芯码不良".Translated();
                    //            listRes[i] = 2;
                    //        }
                    //        else
                    //        {
                    //            m.Result = "OK,";
                    //            m.Remark = "良品".Translated() + ",";

                    //            #region 上传MES
                    //            //上传MES
                    //            if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
                    //            {
                    //                List<string> rfids = new List<string>();
                    //                rfids.Add(m.BarCode);
                    //                var (success, mesage, mesResType) = await CommonMethods.hbgMes.ManyCellInStationAsync(CommonMethods.mesConfig.ProductInStation, CommonMethods.mesConfig.siteCode, CommonMethods.mesConfig.lineCode,
                    //                    CommonMethods.mesConfig.equipNum, CommonMethods.mesConfig.MaterialCode, CommonMethods.mesConfig.mesUserName, rfids);
                    //                if (success) //调用接口成功
                    //                {
                    //                    m.Flag = "1";
                    //                    switch (mesResType[0])
                    //                    {
                    //                        case MesResType.A:// 停线，设备报警停机
                    //                            m.Result += "MES NG";
                    //                            m.Remark += mesage[0];
                    //                            listRes[i] = 3;//10
                    //                            break;
                    //                        case MesResType.B:// 排出
                    //                            m.Result += "MES NG";
                    //                            m.Remark += mesage[0];
                    //                            listRes[i] = 3;//2
                    //                            break;
                    //                        case MesResType.C:// 警示
                    //                        case MesResType.D:// 条码上传OK
                    //                            m.Result += "OK";//MES认为是可以当成良品流下去的
                    //                            m.Remark += mesage[0];
                    //                            break;
                    //                        default:
                    //                            m.Result += "MES NG";
                    //                            m.Remark += mesage[0];
                    //                            listRes[i] = 3;//2
                    //                            break;
                    //                    }
                    //                }
                    //                else
                    //                {
                    //                    m.Flag = "2";
                    //                    m.Result += "MES NG";
                    //                    m.Remark += mesage[0];
                    //                    listRes[i] = 3;//2
                    //                    if (mesage[0].Contains("一个或多个错误"))//调用接口失败
                    //                    {
                    //                        CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short);//反馈MES结果
                    //                    }
                    //                }
                    //            }
                    //            else
                    //            {
                    //                listRes[i] = 3;
                    //                m.Remark += "MES断连";
                    //                m.Flag = "2";
                    //                CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short);//反馈MES结果
                    //            }
                    //            #endregion
                    //        }
                    //        list.Add(m);
                    //    }
                    //}
                    #endregion

                    #region 数据反馈&保存
                    //写入·结果反馈
                    JYResult result = CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue(pf.VarList[1].VarAddress, listRes.ToArray(), PLC.DataType.ArrShort);//判断结果写入PLC
                    if (result != null)
                    {
                        string strres = "进站A工位发送给PLC".Translated() + $",[{pf.VarList[1].VarAddress}]:{string.Join(",", listRes)}";
                        CommonMethods.AddDataMonitorLog(0, strres);
                    }

                    //读取结果显示
                    //数据存储 -异步处理
                    SaveFeedingData(list);
                    CommonMethods.plcDevices[pf.PlcNum - 1].WriteInt16(pf.VarList[0].VarAddress, 0);//置位0
                    #endregion
                }
                catch (Exception ex)
                {

                    LogHelper.Instance.WriteError($"电芯进站A线程数据处理：{ex}", "SysErrorLog");

                }
                sw.Stop();
                ////输出上料数据处理耗时：
                CommonMethods.AddDataMonitorLog(0, "卷芯进站共耗时".Translated() + $"：{sw.Elapsed.TotalMilliseconds}ms");

            }
        }


        /// <summary>
        /// 上料工位B
        /// </summary>
        //上料解析
        private async Task FeedingStationB(JYResult<byte[]> bArrays, object plcModel)
        {
            PlcGroup pf = plcModel as PlcGroup;
            var sw = new Stopwatch();
            if (bArrays.IsSuccess && bArrays.Content != null)
            {
                try
                {
                    sw.Restart();
                    #region 数据初始化
                    //解析数据
                    List<AGearEntity> list = new List<AGearEntity>();//实体
                    List<short> listRes = GetList<short>(8, 2);//默认为1，良品
                    List<bool> listMark = GetList<bool>(8, false);//有料标志
                    List<string> listCode = GetList<string>(8, "");//电芯码
                    List<string> listRemark = GetList<string>(8, "");//备注
                    List<string> listFlag = GetList<string>(8, "0");//是否上传标志
                    List<string> listResult = GetList<string>(8, "OK");//结果
                    List<string> listMesage = GetList<string>(8, "");//mesMesage
                    List<MesResType> listMesResType = GetList<MesResType>(8, MesResType.B);//mesType
                    #endregion

                    // 从D3021开始
                    #region 数据解析
                    byte[] bytes = bArrays.Content.ByteReverse();//高低位转换

                    //有料标志
                    for (int i = 0; i < listMark.Count; i++)
                    {
                        listMark[i] = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2)) == 1 ? true : false;// 从D3021开始
                        if (listMark[i])
                        {
                            #region 数据读取
                            //条码长度
                            int codeLength = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (20 * 2));// 从D3041开始
                            if (codeLength > 0)
                            {
                                //条码
                                listCode[i] = StringLib.GetStringFromByteArrayByEncoding(bytes, (i * 50) + (79 * 2), codeLength, System.Text.Encoding.ASCII).// 从D3100开始
                                   Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim();
                            }
                            else
                            {
                                listCode[i] = "ERROR";
                                //listRes[i] = 2;//条码NG
                            }
                            #endregion

                            #region 数据保存
                            AGearEntity m = new AGearEntity();
                            m.BarCode = listCode[i];
                            m.ChannelNo = (i + 1).ToString();
                            m.TestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                            list.Add(m);
                            #endregion
                        }
                        else
                        {
                            CommonMethods.AddDataMonitorLog(0, "进站上料工位B有料标志为0".Translated() + "通道号".Translated() + $"：{i}");
                        }
                    }
                    #endregion

                    #region 上传MES
                    //上传MES
                    if (list.Count > 0)
                    {
                        if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
                        {
                            //var codeList = list.Select(m => m.BarCode).ToList();
                            //var (success1, mesage1, mesResType1) = await CommonMethods.hbgMes.ManyCellInStationAsync(CommonMethods.mesConfig.ProductInStation, CommonMethods.mesConfig.siteCode, CommonMethods.mesConfig.lineCode,
                            //                CommonMethods.mesConfig.equipNum, CommonMethods.mesConfig.MaterialCode, CommonMethods.mesConfig.mesUserName, codeList);
                            // 创建临时列表收集所有结果
                            var allMesMessages = new List<string>();
                            var allMesResTypes = new List<MesResType>();
                            var allFlags = new List<string>();
                            foreach (var item in list)
                            {
                                // 每次只上传一个条码（封装为List）
                                var singleCodeList = new List<string> { item.BarCode };

                                var (success1, mesage1, mesResType1) = await CommonMethods.hbgMes.ManyCellInStationAsync(
                                    CommonMethods.mesConfig.ProductInStation,
                                    CommonMethods.mesConfig.siteCode,
                                    CommonMethods.mesConfig.lineCode,
                                    CommonMethods.mesConfig.equipNum,
                                    CommonMethods.mesConfig.MaterialCode,
                                    CommonMethods.mesConfig.mesUserName,
                                    singleCodeList);  // 单条码列表
                                if (success1)
                                {
                                    // 收集结果而不是覆盖
                                    allMesMessages.AddRange(mesage1);
                                    allMesResTypes.AddRange(mesResType1);
                                    allFlags.Add("1");
                                }
                                else
                                {
                                    // 收集失败结果
                                    allMesMessages.AddRange(mesage1);
                                    allMesResTypes.AddRange(mesResType1);
                                    allFlags.Add("2");
                                    // 记录失败状态
                                    listRes = GetList<short>(8, 3);
                                    listRemark = GetList<string>(8, "");
                                    if (mesage1.Count > 0 && mesage1[0].Contains("一个或多个错误"))
                                    {
                                        CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short); // 反馈PLC结果
                                    }
                                }
                            }
                            // 将收集的结果赋给主列表
                            listMesage = allMesMessages;
                            listMesResType = allMesResTypes;
                            listFlag = allFlags;
                        }
                        else
                        {
                            listRes = GetList<short>(8, 3);
                            listRemark = GetList<string>(8, "MES断连".Translated());
                            listFlag = GetList<string>(8, "2");

                            CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short);//反馈MES结果
                        }
                    }
                    #endregion

                    #region 数据组合
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (String.IsNullOrEmpty(list[i].BarCode) || list[i].BarCode.Trim() == "ERROR" || !IsAlphaNumeric(list[i].BarCode))
                        {
                            listRes[i] = 2;
                            listResult[i] = "NG";
                            listRemark[i] = "电芯码不良".Translated();
                        }
                        else
                        {
                            int codeIndex = i;//listCode.Count - i - 1;
                            listResult[i] = "OK,";

                            switch (listMesResType[codeIndex])
                            {
                                case MesResType.A:// 停线，设备报警停机
                                    listResult[i] += "MES NG";
                                    listRemark[i] += listMesage[codeIndex];
                                    listRes[i] = 3;//10
                                    break;
                                case MesResType.B:// 排出
                                    listResult[i] += "MES NG";
                                    listRemark[i] += listMesage[codeIndex];
                                    listRes[i] = 3;//2
                                    break;
                                case MesResType.C:// 警示
                                case MesResType.D:// 条码上传OK
                                    listResult[i] += "MES OK";//MES认为是可以当成良品流下去的
                                    listRemark[i] += listMesage[codeIndex];
                                    listRes[i] = 1;
                                    break;
                                default:
                                    listResult[i] += "MES NG";
                                    listRemark[i] += listMesage[codeIndex];
                                    listRes[i] = 3;//2
                                    break;
                            }
                        }

                        list[i].Result = listResult[i].TrimStart(',').TrimEnd(',');
                        list[i].Remark = listRemark[i].TrimStart(',').TrimEnd(',');
                        list[i].Flag = listFlag[i];

                    }
                    #endregion

                    #region 旧
                    //for (int i = 0; i < listCode.Count; i++)
                    //{
                    //    if (listMark[i])
                    //    {
                    //        AGearEntity m = new AGearEntity();
                    //        //string str222 = "";
                    //        m.ChannelNo = (i + 1).ToString();
                    //        m.TestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    //        m.BarCode = listCode[i];
                    //        m.Flag = "0";
                    //        if (String.IsNullOrEmpty(m.BarCode) || m.BarCode.Trim() == "ERROR" || !IsAlphaNumeric(m.BarCode))
                    //        {
                    //            //m.RFID = "NG";
                    //            //m.BarCode = "NG";
                    //            m.Result = "NG";
                    //            m.Remark = "电芯码不良".Translated();
                    //            listRes[i] = 2;
                    //        }
                    //        else
                    //        {
                    //            m.Result = "OK,";
                    //            m.Remark = "良品".Translated() + ",";

                    //            #region 上传MES
                    //            //上传MES
                    //            if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
                    //            {
                    //                List<string> rfids = new List<string>();
                    //                rfids.Add(m.BarCode);
                    //                var (success, mesage, mesResType) = await CommonMethods.hbgMes.ManyCellInStationAsync(CommonMethods.mesConfig.ProductInStation, CommonMethods.mesConfig.siteCode, CommonMethods.mesConfig.lineCode,
                    //                    CommonMethods.mesConfig.equipNum, CommonMethods.mesConfig.MaterialCode, CommonMethods.mesConfig.mesUserName, rfids);
                    //                if (success) //调用接口成功
                    //                {
                    //                    m.Flag = "1";
                    //                    switch (mesResType[0])
                    //                    {
                    //                        case MesResType.A:// 停线，设备报警停机
                    //                            m.Result += "MES NG";
                    //                            m.Remark += mesage[0];
                    //                            listRes[i] = 3;//10
                    //                            break;
                    //                        case MesResType.B:// 排出
                    //                            m.Result += "MES NG";
                    //                            m.Remark += mesage[0];
                    //                            listRes[i] = 3;//2
                    //                            break;
                    //                        case MesResType.C:// 警示
                    //                        case MesResType.D:// 条码上传OK
                    //                            m.Result += "OK";//MES认为是可以当成良品流下去的
                    //                            m.Remark += mesage[0];
                    //                            break;
                    //                        default:
                    //                            m.Result += "MES NG";
                    //                            m.Remark += mesage[0];
                    //                            listRes[i] = 3;//2
                    //                            break;
                    //                    }
                    //                }
                    //                else
                    //                {
                    //                    m.Flag = "2";
                    //                    m.Result += "MES NG";
                    //                    m.Remark += mesage[0];
                    //                    listRes[i] = 3;//2
                    //                    if (mesage[0].Contains("一个或多个错误"))//调用接口失败
                    //                    {
                    //                        CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short);//反馈MES结果
                    //                    }
                    //                }
                    //            }
                    //            else
                    //            {
                    //                listRes[i] = 3;
                    //                m.Remark += "MES断连";
                    //                m.Flag = "2";
                    //                CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short);//反馈MES结果
                    //            }
                    //            #endregion
                    //        }
                    //        list.Add(m);
                    //    }
                    //}
                    #endregion

                    #region 数据反馈&保存
                    //写入·结果反馈
                    JYResult result = CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue(pf.VarList[1].VarAddress, listRes.ToArray(), PLC.DataType.ArrShort);//判断结果写入PLC
                    if (result != null)
                    {
                        string strres = "进站B工位发送给PLC".Translated() + $",[{pf.VarList[1].VarAddress}]:{string.Join(",", listRes)}";
                        CommonMethods.AddDataMonitorLog(0, strres);
                    }

                    //读取结果显示
                    //数据存储 -异步处理
                    SaveFeedingData(list);
                    CommonMethods.plcDevices[pf.PlcNum - 1].WriteInt16(pf.VarList[0].VarAddress, 0);//置位0
                    #endregion
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.WriteError($"电芯进站B线程数据处理：{ex}", "SysErrorLog");

                }

                sw.Stop();
                ////输出上料数据处理耗时：
                CommonMethods.AddDataMonitorLog(0, "卷芯进站共耗时".Translated() + $"：{sw.Elapsed.TotalMilliseconds}ms");

            }
        }

        #region 保存上料数据
        /// <summary>
        /// 保存上料数据到数据
        /// </summary>
        /// <param name="list"></param>
        private async void SaveFeedingData(List<AGearEntity> list)
        {
            //数据的保存
            try
            {
                if (list != null && list.Count > 0)
                {
                    bool b = await CommonMethods.db.AddReturnBoolAsync<AGearEntity>(list);
                    //数据显示 
                    CommonMethods.ShowFeedingDelegate.Invoke(list);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError($"卷芯上料保存处理异常：{ex}", "SysErrorLog");
            }
        }
        #endregion

        #endregion

        #region 下料工位(数据处理)        
        /// <summary>
        /// 电芯出站A
        /// </summary>
        /// <param name="bArrays"></param>
        /// <param name="plcModel"></param>
        //private async Task BlankingStationA(JYResult<byte[]> bArrays, object plcModel)
        //{
        //    PlcGroup pf = plcModel as PlcGroup;
        //    var sw = new Stopwatch();
        //    if (bArrays.IsSuccess && bArrays.Content != null)
        //    {
        //        try
        //        {


        //            #region 初始化数据
        //            sw.Start();
        //            List<BGearEntity> list = new List<BGearEntity>();
        //            List<short> listRes = GetList<short>(3, 2);//默认为1，良品
        //            List<bool> listMark = GetList<bool>(3, false);//有料标志
        //            List<string> listCode = GetList<string>(3, "");//电芯码
        //            List<string> listRemark = GetList<string>(3, "");//备注
        //            List<string> listFlag = GetList<string>(3, "0");//是否上传标志
        //            List<string> listResult = GetList<string>(3, "OK");//结果
        //            List<string> listMesMesage = GetList<string>(3, "");//mesMesage
        //            List<MesResType> listMesResType = GetList<MesResType>(3, MesResType.B);//mesType

        //            //ushort listRes = 1; // 默认为1，良品
        //            string lst_RFIDCodes = ""; // 托杯码
        //            string lst_BarCodes = ""; // 条码

        //            string windSpeed = "";// 风速
        //            string ccdFaceTestDeviceNum1;// 端面检测设备号1
        //            string ccdFaceTestDeviceNum2;// 端面检测设备号2
        //            string ccdFaceTestDeviceNum3;// 端面检测设备号3
        //            string ccdFaceTestDeviceNum4;// 端面检测设备号4
        //            string ccdCylinderTestDeviceNum1;// 柱面检测设备号1
        //            string ccdCylinderTestDeviceNum2;// 柱面检测设备号2
        //            string ccdCylinderTestDeviceNum3;// 柱面检测设备号3

        //            int ccdNegativeTerminalWeldingZone2DInspectionResult = 0; //负极焊接区2D检测结果
        //            int ccdNegativeTerminalWeldingZone2DInspectionNGReasons = 0; //负极焊接区2D检测NG原因（脏污）
        //            int ccdNegativeTerminalWeldingZone2DInspectionNGReasons1 = 0; //负极焊接区2D检测NG原因（划伤）
        //            int ccdNegativeTerminalWeldingZone2DInspectionNGReasons2 = 0; //负极焊接区2D检测NG原因（凹点）

        //            int ccdCoverPlate2DInspectionResult = 0; //盖板2D检测结果
        //            int ccdCoverPlate2DInspectionNGReasons = 0; //盖板2D检测NG原因（脏污）
        //            int ccdCoverPlate2DInspectionNGReasons1 = 0; //盖板2D检测NG原因（划伤）
        //            int ccdCoverPlate2DInspectionNGReasons2 = 0; //盖板2D检测NG原因（凹点）


        //            int ccdNegativeTerminalWeldingZone25DInspectionResult = 0; //负极焊接区2.5D检测结果
        //            int ccdNegativeTerminalWeldingZone25DInspectionNGReasons = 0; //负极焊接区2.5D检测NG原因（脏污）
        //            int ccdNegativeTerminalWeldingZone25DInspectionNGReasons1 = 0; //负极焊接区2.5D检测NG原因（划伤）
        //            int ccdNegativeTerminalWeldingZone25DInspectionNGReasons2 = 0; //负极焊接区2.5D检测NG原因（凹点）


        //            int ccdCoverPlate25DInspectionResult = 0; //盖板2.5D检测结果
        //            int ccdCoverPlate25DInspectionNGReasons = 0; //盖板2.5D检测NG原因（脏污）
        //            int ccdCoverPlate25DInspectionNGReasons1 = 0; //盖板2.5D检测NG原因（划伤）
        //            int ccdCoverPlate25DInspectionNGReasons2 = 0; //盖板2.5D检测NG原因（凹点）


        //            int ccdTerminalPost2DInspectionResult = 0; //极柱2D检测结果
        //            int ccdTerminalPost2DInspectionNGReasons = 0; //极柱2D检测NG原因（脏污）
        //            int ccdTerminalPost2DInspectionNGReasons1 = 0; //极柱2D检测NG原因（划伤）
        //            int ccdTerminalPost2DInspectionNGReasons2 = 0; //极柱2D检测NG原因（凹点）
        //            int ccdTerminalPost2DInspectionNGReasons3 = 0; //极柱2D检测NG原因（残缺）


        //            int ccdTerminalPost3DInspectionResult = 0; //极柱3D检测结果
        //            int ccdTerminalPost3DInspectionNGReasons = 0; //极柱3D检测NG原因（脏污）
        //            int ccdTerminalPost3DInspectionNGReasons1 = 0; //极柱3D检测NG原因（划伤）
        //            int ccdTerminalPost3DInspectionNGReasons2 = 0; //极柱3D检测NG原因（凹点）
        //            int ccdTerminalPost3DInspectionNGReasons3 = 0; //极柱3D检测NG原因（残缺）



        //            int ccdSealingNail2DInspectionResult = 0; //密封钉2D检测结果
        //            int ccdSealingNail2DInspectionNGReasons = 0; //密封钉2D检测NG原因（铝钉焊接）

        //            int ccdSealingNail3DInspectionResult = 0; //密封钉3D检测结果
        //            int ccdSealingNail3DInspectionNGReasons = 0; //密封钉3D检测NG原因（铝钉焊接）

        //            int ccdTopFillet25DInspectionResult = 0; //上部R角2.5D检测结果
        //            int ccdTopFillet25DInspectionNGReasons = 0; //上部R角2.5D检测NG原因（凹点）

        //            int ccdBottomFillet25DInspectionResult = 0; //底部R角2.5D检测结果
        //            int ccdBottomFillet25DInspectionNGReasons = 0; //底部R角2.5D检测NG原因（凹点）

        //            int ccdCylindricalSurface25DInspectionResult = 0; //柱面2.5D检测结果
        //            int ccdCylindricalSurface25DInspectionNGReasons = 0; //柱面2.5D检测NG原因（生锈）
        //            int ccdCylindricalSurface25DInspectionNGReasons1 = 0; //柱面2.5D检测NG原因（划伤）
        //            int ccdCylindricalSurface25DInspectionNGReasons2 = 0; //柱面2.5D检测NG原因（凹点）
        //            int ccdCylindricalSurface25DInspectionNGReasons3 = 0; //柱面2.5D检测NG原因（模糊）


        //            int ccdCylindricalSurface3DInspectionResult = 0; //柱面3D检测结果
        //            int ccdCylindricalSurface3DInspectionNGReasons = 0; //柱面3D检测NG原因（生锈）
        //            int ccdCylindricalSurface3DInspectionNGReasons1 = 0; //柱面3D检测NG原因（划伤）
        //            int ccdCylindricalSurface3DInspectionNGReasons2 = 0; //柱面3D检测NG原因（凹点）
        //            int ccdCylindricalSurface3DInspectionNGReasons3 = 0; //柱面3D检测NG原因（模糊）


        //            int[] ccdTestResult = new int[12];//ccd检测结果

        //            string result = "";//总结果
        //            string info = "";//NG详情

        //            #endregion

        //            #region 数据解析
        //            byte[] bytes = bArrays.Content.ByteReverse();

        //            //有料标志
        //            for (int i = 0; i < listMark.Count; i++)
        //            {
        //                listMark[i] = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2)) == 1 ? true : false;// 从D4021开始
        //                if (listMark[i])
        //                {
        //                    #region 数据读取
        //                    //条码长度
        //                    int codeLength = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (20 * 2));// 从D4041开始
        //                    if (codeLength > 0)
        //                    {
        //                        //条码
        //                        listCode[i] = StringLib.GetStringFromByteArrayByEncoding(bytes, (i * 50) + (79 * 2), codeLength, System.Text.Encoding.ASCII).// 从D4100开始
        //                           Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim();
        //                    }
        //                    else { listCode[i] = "ERROR"; }

        //                    #region 旧
        //                    //windSpeed = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 2) + (579 * 2), DataFormat.CDAB).ToString("f3"); // 风速 D4600 579
        //                    //ccdFaceTestDeviceNum1 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (595 * 2), DataFormat.CDAB).ToString("f3"); // 端面检测设备号1 D4616 595
        //                    //ccdFaceTestDeviceNum2 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (597 * 2), DataFormat.CDAB).ToString("f3"); // 端面检测设备号2 D4618 597
        //                    //ccdFaceTestDeviceNum3 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (599 * 2), DataFormat.CDAB).ToString("f3"); // 端面检测设备号3 D4620 599
        //                    //ccdFaceTestDeviceNum4 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (601 * 2), DataFormat.CDAB).ToString("f3"); // 端面检测设备号4 D4622 601

        //                    //ccdCylinderTestDeviceNum1 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (659 * 2), DataFormat.CDAB).ToString("f3"); // 柱面检测设备号1 D4680 659
        //                    //ccdCylinderTestDeviceNum2 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (661 * 2), DataFormat.CDAB).ToString("f3"); // 柱面检测设备号2 D4682 661
        //                    //ccdCylinderTestDeviceNum3 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (663 * 2), DataFormat.CDAB).ToString("f3"); // 柱面检测设备号3 D4684 663

        //                    //ccdPosFaceTestResult = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (707 * 2));// 正极端面检测结果 D4728 707
        //                    //ccdNegFaceTestResult = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (715 * 2));// 负极端面检测结果 D4736 715
        //                    //ccdBeforeCoatedCylinderTestResult = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (723 * 2));// 包膜前圆柱面检测结果 D4744 723
        //                    //ccdPosCylinderTestResult = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (731 * 2));// 正极柱检测结果 D4752 731
        //                    //ccdNegCylinderTestResult = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (739 * 2));// 负极柱检测结果 D4760 739

        //                    //result = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (747 * 2)).ToString("f3");// 总结果 D4768 747
        //                    //info = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (755 * 2)).ToString("f3");// NG详情 D4776 755
        //                    #endregion

        //                    windSpeed = GetValueFromByteArray(bArrays.Content, "windSpeed", i * 4); // 风速 D4600 579
        //                    ccdFaceTestDeviceNum1 = GetValueFromByteArray(bArrays.Content, "ccdFaceTestDeviceNum1", (i * 8) * 2);  // 端面检测设备号1 D4616 595
        //                    ccdFaceTestDeviceNum2 = GetValueFromByteArray(bArrays.Content, "ccdFaceTestDeviceNum2", (i * 8) * 2);  // 端面检测设备号2 D4618 597
        //                    ccdFaceTestDeviceNum3 = GetValueFromByteArray(bArrays.Content, "ccdFaceTestDeviceNum3", (i * 8) * 2);  // 端面检测设备号3 D4620 599
        //                    ccdFaceTestDeviceNum4 = GetValueFromByteArray(bArrays.Content, "ccdFaceTestDeviceNum4", (i * 8) * 2);  // 端面检测设备号4 D4622 601

        //                    ccdCylinderTestDeviceNum1 = GetValueFromByteArray(bArrays.Content, "ccdCylinderTestDeviceNum1", (i * 8) * 2); // 柱面检测设备号1 D4680 659
        //                    ccdCylinderTestDeviceNum2 = GetValueFromByteArray(bArrays.Content, "ccdCylinderTestDeviceNum2", (i * 8) * 2); // 柱面检测设备号2 D4682 661
        //                    ccdCylinderTestDeviceNum3 = GetValueFromByteArray(bArrays.Content, "ccdCylinderTestDeviceNum3", (i * 8) * 2); // 柱面检测设备号3 D4684 663

        //                    //ccdPosFaceTestResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdPosFaceTestResult", (i * 2)));// 正极端面检测结果 D4728 707
        //                    //ccdNegFaceTestResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegFaceTestResult", (i * 2)));// 负极端面检测结果 D4736 715
        //                    //ccdBeforeCoatedCylinderTestResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdBeforeCoatedCylinderTestResult", (i * 2)));// 包膜前圆柱面检测结果 D4744 723
        //                    //ccdPosCylinderTestResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdPosCylinderTestResult", (i * 2)));// 正极柱检测结果 D4752 731
        //                    //ccdNegCylinderTestResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegCylinderTestResult", (i * 2)));// 负极柱检测结果 D4760 739

        //                    ccdNegativeTerminalWeldingZone2DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone2DInspectionResult", (i * 2))); // 负极焊接区2D检测结果
        //                    ccdNegativeTerminalWeldingZone2DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone2DInspectionNGReasons", (i * 2))); // 负极焊接区2D检测NG原因
        //                    ccdNegativeTerminalWeldingZone2DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone2DInspectionNGReasons1", (i * 2))); // 负极焊接区2D检测NG原因
        //                    ccdNegativeTerminalWeldingZone2DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone2DInspectionNGReasons2", (i * 2))); // 负极焊接区2D检测NG原因

        //                    ccdCoverPlate2DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate2DInspectionResult", (i * 2))); // 盖板2D检测结果
        //                    ccdCoverPlate2DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate2DInspectionNGReasons", (i * 2))); // 盖板2D检测NG原因
        //                    ccdCoverPlate2DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate2DInspectionNGReasons1", (i * 2))); // 盖板2D检测NG原因
        //                    ccdCoverPlate2DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate2DInspectionNGReasons2", (i * 2))); // 盖板2D检测NG原因

        //                    ccdNegativeTerminalWeldingZone25DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone25DInspectionResult", (i * 2))); // 负极焊接区2.5D检测结果
        //                    ccdNegativeTerminalWeldingZone25DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone25DInspectionNGReasons", (i * 2))); // 负极焊接区2.5D检测NG原因
        //                    ccdNegativeTerminalWeldingZone25DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone25DInspectionNGReasons1", (i * 2))); // 负极焊接区2.5D检测NG原因
        //                    ccdNegativeTerminalWeldingZone25DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone25DInspectionNGReasons2", (i * 2))); // 负极焊接区2.5D检测NG原因

        //                    ccdCoverPlate25DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate25DInspectionResult", (i * 2))); // 盖板2.5D检测结果
        //                    ccdCoverPlate25DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate25DInspectionNGReasons", (i * 2))); // 盖板2.5D检测NG原因
        //                    ccdCoverPlate25DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate25DInspectionNGReasons1", (i * 2))); // 盖板2.5D检测NG原因
        //                    ccdCoverPlate25DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate25DInspectionNGReasons2", (i * 2))); // 盖板2.5D检测NG原因

        //                    ccdTerminalPost2DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost2DInspectionResult", (i * 2))); // 极柱2D检测结果
        //                    ccdTerminalPost2DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost2DInspectionNGReasons", (i * 2))); // 极柱2D检测NG原因
        //                    ccdTerminalPost2DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost2DInspectionNGReasons1", (i * 2))); // 极柱2D检测NG原因
        //                    ccdTerminalPost2DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost2DInspectionNGReasons2", (i * 2))); // 极柱2D检测NG原因
        //                    ccdTerminalPost2DInspectionNGReasons3 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost2DInspectionNGReasons3", (i * 2))); // 极柱2D检测NG原因

        //                    ccdTerminalPost3DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost3DInspectionResult", (i * 2))); // 极柱3D检测结果
        //                    ccdTerminalPost3DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost3DInspectionNGReasons", (i * 2))); // 极柱3D检测NG原因
        //                    ccdTerminalPost3DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost3DInspectionNGReasons1", (i * 2))); // 极柱3D检测NG原因
        //                    ccdTerminalPost3DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost3DInspectionNGReasons2", (i * 2))); // 极柱3D检测NG原因
        //                    ccdTerminalPost3DInspectionNGReasons3 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost3DInspectionNGReasons3", (i * 2))); // 极柱3D检测NG原因

        //                    ccdSealingNail2DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdSealingNail2DInspectionResult", (i * 2))); // 密封钉2D检测结果
        //                    ccdSealingNail2DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdSealingNail2DInspectionNGReasons", (i * 2))); // 密封钉2D检测NG原因

        //                    ccdSealingNail3DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdSealingNail3DInspectionResult", (i * 2))); // 密封钉3D检测结果
        //                    ccdSealingNail3DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdSealingNail3DInspectionNGReasons", (i * 2))); // 密封钉3D检测NG原因

        //                    ccdTopFillet25DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTopFillet25DInspectionResult", (i * 2))); // 上部R角2.5D检测结果
        //                    ccdTopFillet25DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTopFillet25DInspectionNGReasons", (i * 2))); // 上部R角2.5D检测NG原因

        //                    ccdBottomFillet25DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdBottomFillet25DInspectionResult", (i * 2))); // 底部R角2.5D检测结果
        //                    ccdBottomFillet25DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdBottomFillet25DInspectionNGReasons", (i * 2))); // 底部R角2.5D检测NG原因

        //                    ccdCylindricalSurface25DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface25DInspectionResult", (i * 2))); // 柱面2.5D检测结果
        //                    ccdCylindricalSurface25DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface25DInspectionNGReasons", (i * 2))); // 柱面2.5D检测NG原因
        //                    ccdCylindricalSurface25DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface25DInspectionNGReasons1", (i * 2))); // 柱面2.5D检测NG原因
        //                    ccdCylindricalSurface25DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface25DInspectionNGReasons2", (i * 2))); // 柱面2.5D检测NG原因
        //                    ccdCylindricalSurface25DInspectionNGReasons3 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface25DInspectionNGReasons3", (i * 2))); // 柱面2.5D检测NG原因

        //                    ccdCylindricalSurface3DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface3DInspectionResult", (i * 2))); // 柱面3D检测结果
        //                    ccdCylindricalSurface3DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface3DInspectionNGReasons", (i * 2))); // 柱面3D检测NG原因
        //                    ccdCylindricalSurface3DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface3DInspectionNGReasons1", (i * 2))); // 柱面3D检测NG原因
        //                    ccdCylindricalSurface3DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface3DInspectionNGReasons2", (i * 2))); // 柱面3D检测NG原因
        //                    ccdCylindricalSurface3DInspectionNGReasons3 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface3DInspectionNGReasons3", (i * 2))); // 柱面3D检测NG原因

        //                    ccdTestResult[0] = ccdNegativeTerminalWeldingZone2DInspectionResult;
        //                    ccdTestResult[1] = ccdCoverPlate2DInspectionResult;
        //                    ccdTestResult[2] = ccdNegativeTerminalWeldingZone25DInspectionResult;
        //                    ccdTestResult[3] = ccdCoverPlate25DInspectionResult;
        //                    ccdTestResult[4] = ccdTerminalPost2DInspectionResult;
        //                    ccdTestResult[5] = ccdTerminalPost3DInspectionResult;
        //                    ccdTestResult[6] = ccdSealingNail2DInspectionResult;
        //                    ccdTestResult[7] = ccdSealingNail3DInspectionResult;
        //                    ccdTestResult[8] = ccdTopFillet25DInspectionResult;
        //                    ccdTestResult[9] = ccdBottomFillet25DInspectionResult;
        //                    ccdTestResult[10] = ccdCylindricalSurface25DInspectionResult;
        //                    ccdTestResult[11] = ccdCylindricalSurface3DInspectionResult;


        //                    result = GetValueFromByteArray(bArrays.Content, "result", (i * 2));// 总结果 D4768 747
        //                    info = GetValueFromByteArray(bArrays.Content, "info", (i * 2));// NG详情 D4776 755

        //                    lst_RFIDCodes = "";//StringLib.GetStringFromByteArrayByEncoding(bytes, 0, 39, Encoding.ASCII).Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim(); // RFID D3200-3219
        //                    lst_BarCodes = listCode[i];

        //                    #endregion
        //                }
        //                else
        //                {
        //                    CommonMethods.AddDataMonitorLog(0, "出站下料工位A有料标志为0".Translated() + "通道号".Translated() + $"：{i}");
        //                }

        //                #region 数据保存
        //                BGearEntity m = new BGearEntity
        //                {
        //                    ChannelNo = (i + 1).ToString(),
        //                    TestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
        //                    RFID = lst_RFIDCodes,
        //                    BarCode = lst_BarCodes,
        //                    WindSpeed = windSpeed,
        //                    WindDeviceNum = "A",
        //                    CCDFaceTestDeviceNum1 = "A",
        //                    CCDFaceTestDeviceNum2 = "A",
        //                    CCDFaceTestDeviceNum3 = "A",
        //                    CCDFaceTestDeviceNum4 = "A",

        //                    CCDCylinderTestDeviceNum1 = "A",
        //                    CCDCylinderTestDeviceNum2 = "A",
        //                    CCDCylinderTestDeviceNum3 = "A",

        //                    //CCDPosFaceTestResult = ccdPosFaceTestResult == 1 ? "OK" : "NG",
        //                    //CCDNegFaceTestResult = ccdNegFaceTestResult == 1 ? "OK" : "NG",
        //                    //CCDBeforeCoatedCylinderTestResult = ccdBeforeCoatedCylinderTestResult == 1 ? "OK" : "NG",
        //                    //CCDPosCylinderTestResult = ccdPosCylinderTestResult == 1 ? "OK" : "NG",
        //                    //CCDNegCylinderTestResult = ccdNegCylinderTestResult == 1 ? "OK" : "NG",

        //                    CCDNegativeTerminalWeldingZone2DInspectionResult = ccdNegativeTerminalWeldingZone2DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDNegativeTerminalWeldingZone2DInspectionNGReasons = CombineNGReasons
        //                                                                         (GetNGReasons(ccdNegativeTerminalWeldingZone2DInspectionNGReasons, "UI20801"),
        //                                                                          GetNGReasons(ccdNegativeTerminalWeldingZone2DInspectionNGReasons1, "UI21301"),
        //                                                                          GetNGReasons(ccdNegativeTerminalWeldingZone2DInspectionNGReasons2, "UI127")),
        //                    CCDCoverPlate2DInspectionResult = ccdCoverPlate2DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDCoverPlate2DInspectionNGReasons = CombineNGReasons
        //                                                        (GetNGReasons(ccdCoverPlate2DInspectionNGReasons, "UI20801"),
        //                                                         GetNGReasons(ccdCoverPlate2DInspectionNGReasons1, "UI21301"),
        //                                                         GetNGReasons(ccdCoverPlate2DInspectionNGReasons2, "UI127")),
        //                    CCDNegativeTerminalWeldingZone25DInspectionResult = ccdNegativeTerminalWeldingZone25DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDNegativeTerminalWeldingZone25DInspectionNGReasons = CombineNGReasons
        //                                                                          (GetNGReasons(ccdNegativeTerminalWeldingZone25DInspectionNGReasons, "UI20801"),
        //                                                                           GetNGReasons(ccdNegativeTerminalWeldingZone25DInspectionNGReasons1, "UI21301"),
        //                                                                           GetNGReasons(ccdNegativeTerminalWeldingZone25DInspectionNGReasons2, "UI127")),
        //                    CCDCoverPlate25DInspectionResult = ccdCoverPlate25DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDCoverPlate25DInspectionNGReasons = CombineNGReasons
        //                                                         (GetNGReasons(ccdCoverPlate25DInspectionNGReasons, "UI20801"),
        //                                                          GetNGReasons(ccdCoverPlate25DInspectionNGReasons1, "UI21301"),
        //                                                          GetNGReasons(ccdCoverPlate25DInspectionNGReasons2, "UI127")),
        //                    CCDTerminalPost2DInspectionResult = ccdTerminalPost2DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDTerminalPost2DInspectionNGReasons = CombineNGReasons
        //                                                         (GetNGReasons(ccdCoverPlate25DInspectionNGReasons, "UI20801"),
        //                                                          GetNGReasons(ccdTerminalPost2DInspectionNGReasons1, "UI21301"),
        //                                                          GetNGReasons(ccdTerminalPost2DInspectionNGReasons2, "UI127"),
        //                                                          GetNGReasons(ccdTerminalPost2DInspectionNGReasons3, "UI125")),
        //                    CCDTerminalPost3DInspectionResult = ccdTerminalPost3DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDTerminalPost3DInspectionNGReasons = CombineNGReasons
        //                                                         (GetNGReasons(ccdTerminalPost3DInspectionNGReasons, "UI20801"),
        //                                                          GetNGReasons(ccdTerminalPost3DInspectionNGReasons1, "UI21301"),
        //                                                          GetNGReasons(ccdTerminalPost3DInspectionNGReasons2, "UI127"),
        //                                                          GetNGReasons(ccdTerminalPost3DInspectionNGReasons3, "UI125")),
        //                    CCDSealingNail2DInspectionResult = ccdSealingNail2DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDSealingNail2DInspectionNGReasons = "",
        //                    CCDSealingNail3DInspectionResult = ccdSealingNail3DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDSealingNail3DInspectionNGReasons = "",
        //                    CCDTopFillet25DInspectionResult = ccdTopFillet25DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDTopFillet25DInspectionNGReasons = CombineNGReasons
        //                                                         (GetNGReasons(ccdTopFillet25DInspectionNGReasons, "UI127")),
        //                    CCDBottomFillet25DInspectionResult = ccdBottomFillet25DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDBottomFillet25DInspectionNGReasons = CombineNGReasons
        //                                                         (GetNGReasons(ccdBottomFillet25DInspectionNGReasons, "UI127")),
        //                    CCDCylindricalSurface25DInspectionResult = ccdCylindricalSurface25DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDCylindricalSurface25DInspectionNGReasons = CombineNGReasons
        //                                                                 (GetNGReasons(ccdCylindricalSurface25DInspectionNGReasons, "UI128"),
        //                                                                  GetNGReasons(ccdCylindricalSurface25DInspectionNGReasons1, "UI21301"),
        //                                                                  GetNGReasons(ccdCylindricalSurface25DInspectionNGReasons2, "UI127"),
        //                                                                  GetNGReasons(ccdCylindricalSurface25DInspectionNGReasons3, "UI00404")),
        //                    CCDCylindricalSurface3DInspectionResult = ccdCylindricalSurface3DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDCylindricalSurface3DInspectionNGReasons = CombineNGReasons
        //                                                                 (GetNGReasons(ccdCylindricalSurface3DInspectionNGReasons, "UI128"),
        //                                                                  GetNGReasons(ccdCylindricalSurface3DInspectionNGReasons1, "UI21301"),
        //                                                                  GetNGReasons(ccdCylindricalSurface3DInspectionNGReasons2, "UI127"),
        //                                                                  GetNGReasons(ccdCylindricalSurface3DInspectionNGReasons3, "UI00404")),



        //                    //Flag = "0",
        //                    Flag1 = "2",
        //                    Result = result,
        //                    Info = info,
        //                    MaterialCode = CommonMethods.mesConfig.MaterialCode,
        //                };

        //                list.Add(m);
        //                #endregion
        //            }
        //            #endregion

        //            #region 数据上传
        //            if (list.Count > 0)
        //            {
        //                if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
        //                {
        //                    //var (success, mesage, mesResType) = await CommonMethods.hbgMes.ManyCellOutStationAsync(CommonMethods.mesConfig.ProductOutStation, CommonMethods.mesConfig.siteCode, CommonMethods.mesConfig.lineCode,
        //                    //             CommonMethods.mesConfig.equipNum, CommonMethods.mesConfig.MaterialCode, CommonMethods.mesConfig.ModelName, CommonMethods.mesConfig.mesUserName, list, 1, CommonMethods.mesConfig.materialLotCodeLocator);
        //                    // 初始化结果收集列表
        //                    var tempMesMessages = new List<string>();
        //                    var tempMesResTypes = new List<MesResType>();
        //                    var tempFlags = new List<string>();
        //                    foreach (var item in list)
        //                    {
        //                        // 创建单个电池的列表
        //                        var singleBatteryList = new List<BGearEntity> { item };

        //                        // 调用MES接口（每次只传一个电池）
        //                        var (success, mesage, mesResType) = await CommonMethods.hbgMes.ManyCellOutStationAsync(
        //                            CommonMethods.mesConfig.ProductOutStation,
        //                            CommonMethods.mesConfig.siteCode,
        //                            CommonMethods.mesConfig.lineCode,
        //                            CommonMethods.mesConfig.equipNum,
        //                            CommonMethods.mesConfig.MaterialCode,
        //                            CommonMethods.mesConfig.ModelName,
        //                            CommonMethods.mesConfig.mesUserName,
        //                            singleBatteryList,
        //                            1,
        //                            CommonMethods.mesConfig.materialLotCodeLocator);
        //                        if (success)
        //                        {
        //                            // 收集成功结果
        //                            tempMesMessages.AddRange(mesage);
        //                            tempMesResTypes.AddRange(mesResType);
        //                            tempFlags.Add("1");
        //                        }
        //                        else
        //                        {
        //                            // 收集失败结果
        //                            tempMesMessages.AddRange(mesage);
        //                            tempMesResTypes.AddRange(mesResType);
        //                            tempFlags.Add("2");

        //                            // 记录失败状态
        //                            listRes = GetList<short>(8, 3);
        //                            listRemark = GetList<string>(8, "");
        //                            if (mesage.Count > 0 && mesage[0].Contains("一个或多个错误"))
        //                            {
        //                                CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short); // 反馈PLC结果
        //                            }
        //                        }
        //                    }
        //                    // 将收集的结果赋给主列表
        //                    listMesMesage = tempMesMessages;
        //                    listMesResType = tempMesResTypes;
        //                    listFlag = tempFlags;

        //                }
        //                else
        //                {
        //                    listRes = GetList<short>(8, 3);
        //                    listRemark = GetList<string>(8, "MES断连".Translated() + ",");
        //                    listFlag = GetList<string>(8, "2");

        //                    CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short);//反馈MES结果
        //                }

        //            }
        //            UpProducResultParam(list);
        //            #endregion

        //            #region 数据组合
        //            for (int i = 0; i < list.Count; i++)
        //            {
        //                if (String.IsNullOrEmpty(list[i].BarCode) || list[i].BarCode.Trim() == "ERROR" || !IsAlphaNumeric(list[i].BarCode))
        //                {
        //                    listRes[i] = 2;
        //                    listResult[i] = "NG";
        //                    list[i].Info = "电芯码不良".Translated();
        //                }
        //                else
        //                {
        //                    string strErr = "";
        //                    short a = (short)GetResult(ccdTestResult, ref strErr);
        //                    listResult[i] = a == 12 ? "OK" : "NG";
        //                    list[i].Info = strErr;

        //                    // 本地判断OK，MES判断OK
        //                    if (listResult[i] == "OK" && listMesResType[i] == MesResType.D)
        //                    {
        //                        listResult[i] += ",MES OK";
        //                        list[i].Info = "良品".Translated();
        //                        listRes[i] = 1;
        //                    }
        //                    // 本地判断OK，MES判断NG
        //                    else if (listResult[i] == "OK" && listMesResType[i] != MesResType.D)
        //                    {
        //                        switch (listMesResType[i])
        //                        {
        //                            case MesResType.A: // 停线，设备报警停机
        //                                listResult[i] += ",MES NG";
        //                                listRemark[i] += $"A,{listMesMesage[i]}";
        //                                listRes[i] = 3;//10
        //                                break;
        //                            case MesResType.B: // MES不良
        //                                listResult[i] += ",MES NG";
        //                                listRemark[i] += $"B,{listMesMesage[i]}";
        //                                listRes[i] = 3;//9
        //                                break;
        //                            case MesResType.C: // 警示
        //                                listResult[i] += ",MES OK"; // MES认为是可以当成良品流下去的
        //                                listRemark[i] += $"Alarm:{listMesMesage[i]}";
        //                                listRes[i] = 1;
        //                                break;
        //                            case MesResType.D: // 条码上传OK
        //                                listResult[i] += ",MES OK";
        //                                listRemark[i] += $"D,{listMesMesage[i]}";
        //                                listRes[i] = 1;
        //                                break;
        //                            default:
        //                                listResult[i] += ",MES NG";
        //                                listRemark[i] += $"{listMesMesage[i]}";
        //                                listRes[i] = 3;//9
        //                                break;
        //                        }
        //                    }
        //                    // 本地判断NG，MES判断OK
        //                    else if (listResult[i] == "NG" && listMesResType[i] == MesResType.D)
        //                    {
        //                        listResult[i] += ",MES OK";
        //                        listRemark[i] += $"D,{listMesMesage[i]}";
        //                        listRes[i] = 1;
        //                    }
        //                    // 本地判断NG，MES判断NG
        //                    else if (listResult[i] == "NG" && listMesResType[i] != MesResType.D)
        //                    {
        //                        listResult[i] += ",MES NG";
        //                        listRemark[i] += $"{listMesResType[i].ToString()},{listMesMesage[i]}";
        //                        listRes[i] = 3;//9
        //                    }
        //                    // 其他情况
        //                    else
        //                    {
        //                        listResult[i] += ",MES NG";
        //                        listRemark[i] += listMesMesage[i];
        //                        listRes[i] = 3;//9
        //                    }
        //                }
        //                list[i].Result = listResult[i].TrimStart(',').TrimEnd(',');
        //                list[i].Remark = listRemark[i].TrimStart(',').TrimEnd(',');
        //                list[i].Flag = listFlag[i];
        //            }
        //            #endregion

        //            #region 判断电芯是否属于复投
        //            for (int i = 0; i < list.Count; i++)
        //            {
        //                if (!(String.IsNullOrEmpty(list[i].BarCode) || list[i].BarCode.Trim() == "ERROR" || !IsAlphaNumeric(list[i].BarCode)))
        //                {
        //                    List<BGearEntity> listBGearEntity = CommonMethods.db.QuerySqlList<BGearEntity>(CommonMethods.dBSQL.GetOutCcdResultSql(list[i].BarCode));
        //                    if (listBGearEntity != null && listBGearEntity.Count > 0)
        //                    {
        //                        // 属于复投电芯（上一次CCD检测结果NG）
        //                        // 本次CCD检测结果NG
        //                        if (!GetCcdResult(list[i])) { listRes[i] = 4; }
        //                    }
        //                }
        //            }
        //            #endregion

        //            #region 数据反馈&上传
        //            if (pf.IsFeedbackPlc)
        //            {
        //                //CommonMethods.plcDevices[pf.PlcNum - 1].WriteInt16(pf.VarList[1].VarAddress, (short)listRes); // 反馈PLC结果
        //                //写入·结果反馈
        //                JYResult result1 = CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue(pf.VarList[1].VarAddress, listRes.ToArray(), PLC.DataType.ArrShort);//判断结果写入PLC
        //                if (result1 != null)
        //                {
        //                    string strres = "出站A工位发送给PLC".Translated() + $",[{pf.VarList[1].VarAddress}]:{string.Join(",", listRes)}";
        //                    CommonMethods.AddDataMonitorLog(0, strres);
        //                }
        //            }

        //            CommonMethods.plcDevices[pf.PlcNum - 1].WriteInt16(pf.VarList[0].VarAddress, (short)0); // 置位0
        //            LogHelper.Instance.WriteLog($"A出站发送信息给PLC：{string.Join(",", listRes)}");

        //            // 数据存储 - 异步处理
        //            SaveBlankingData(list);

        //            //if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
        //            //{
        //            //    UpProducResultParam(list);
        //            //}

        //            #endregion

        //        }
        //        catch (Exception ex)
        //        {
        //            LogHelper.Instance.WriteError($"电芯出站A线程数据处理：{ex}", "SysErrorLog");
        //        }

        //        sw.Stop();

        //        // 输出上料数据处理耗时：
        //        CommonMethods.AddDataMonitorLog(0, "电芯出站A共耗时".Translated() + $"：{sw.Elapsed.TotalMilliseconds}ms");
        //    }
        //}
        /// <summary>
        /// 电芯出站A
        /// </summary>
        /// <param name="bArrays"></param>
        /// <param name="plcModel"></param>
        private async Task BlankingStationA(JYResult<byte[]> bArrays, object plcModel)
        {
            PlcGroup pf = plcModel as PlcGroup;
            var sw = new Stopwatch();
            if (bArrays.IsSuccess && bArrays.Content != null)
            {
                try
                {
                    #region 初始化数据
                    sw.Start();
                    List<BGearEntity> list = new List<BGearEntity>();
                    List<short> listRes = GetList<short>(3, 2);//默认为1，良品
                    List<bool> listMark = GetList<bool>(3, false);//有料标志
                    List<string> listCode = GetList<string>(3, "");//电芯码
                    List<string> listRemark = GetList<string>(3, "");//备注
                    List<string> listFlag = GetList<string>(3, "0");//是否上传标志
                    List<string> listResult = GetList<string>(3, "OK");//结果
                    List<string> listMesMesage = GetList<string>(3, "");//mesMesage
                    List<MesResType> listMesResType = GetList<MesResType>(3, MesResType.B);//mesType

                    //ushort listRes = 1; // 默认为1，良品
                    string lst_RFIDCodes = ""; // 托杯码
                    string lst_BarCodes = ""; // 条码

                  


                    int[] ccdTestResult = new int[12];//ccd检测结果

                    #endregion

                    #region 数据解析
                    byte[] bytes = bArrays.Content.ByteReverse();

                    //有料标志
                    for (int i = 0; i < listMark.Count; i++)
                    {
                        var TT = new AGearEntity();
                        BGearEntity m = new BGearEntity();
                        listMark[i] = true;//ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2)) == 1 ? true : false;// 从D4021开始
                        if (listMark[i])
                        {
                            #region 数据读取
                            //条码长度 //D3200起
                            int codeLength = 20;// ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (20 * 2));// 
                            listCode[i] = StringLib.GetStringFromByteArrayByEncoding(bArrays.Content, (i * 20 * 2), codeLength * 2, System.Text.Encoding.ASCII).// 从D4100开始
                                 Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim();
                            if (String.IsNullOrEmpty(listCode[i]) || listCode[i].Trim() == "ERROR")
                            { listCode[i] = "ERROR"; }
                            

                            #region CCD
                            //芯包信息1  D3300~D3326
                            //芯包信息2  D3330~D3356
                            //芯包信息3  D3360~D3386
                            //int[,] CCD_Data = new int[3, 27];//芯包CCD信息1,2,3
                            for (int j = 0; j < 27; j++)
                            {
                                m.CCD_Data[i, j] = ShortLib.GetShortFromByteArray(bArrays.Content, 200 + i * 30 * 2 + j * 2, DataFormat.CDAB);
                            }
                            #endregion



                            //ccdNegativeTerminalWeldingZone2DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone2DInspectionResult", (i * 2))); // 负极焊接区2D检测结果
                            //ccdTestResult[0] = ccdNegativeTerminalWeldingZone2DInspectionResult;
                           

                            //result = GetValueFromByteArray(bArrays.Content, "result", (i * 2));// 总结果 D4768 747
                           // info = GetValueFromByteArray(bArrays.Content, "info", (i * 2));// NG详情 D4776 755

                            lst_RFIDCodes = "";//StringLib.GetStringFromByteArrayByEncoding(bytes, 0, 39, Encoding.ASCII).Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim(); // RFID D3200-3219
                            m.BarCode = listCode[i];

                            #region new

                            //var EX = CommonMethods.db.QuerySqlList<Challenge>(CommonMethods.dBSQL.GetChallengeCode(m.CSBYHCODEA));
                            //for (int j = 0; j < EX.Count; j++)
                            //{
                            //    if (string.Compare(EX[j].ChallengeBarCode, m.CSBYHCODEA) == 0)
                            //    {
                            //        m.Remark += "(极限件," + EX[j].CodeMessage + "," + EX[j].WeldingCCD + ")";
                            //        ChallengeFlag = 1;
                            //    }
                            //}
                            //查询进站时间数据
                          
                            var w = CommonMethods.db.QuerySqlList<AGearEntity>(CommonMethods.dBSQL.GetInTime(listCode[i]));
                            //获取新一行数据
                            if (w.Count > 0)
                                TT = w[w.Count - 1];
                            //
                            //if (w.Count > 0)
                            //    TT = w[0];
                            if (TT.TestTime != null)
                                m.ScanTime[0] = TT.TestTime;
                            else
                                m.ScanTime[0] = "";
                            //芯包出站时间
                            m.ScanTime[1] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                           
                            //不良代码判定
                            List<string> NGcodeList = new List<string>();
                           
                            NGcodeList = NGWGJcode(m.CCD_Data, i);
                            #region //电芯CCD判定结果 1 0K 0NG 2缺图
                            m.CCDResult1 = m.CCD_Data[i, 0] == 1 ? "OK" : (m.CCD_Data[i, 0] == 0 ? "NG" : "缺图");
                            m.CCDResult2 = m.CCD_Data[i, 1] == 1 ? "OK" : (m.CCD_Data[i, 1] == 0 ? "NG" : "缺图");
                            m.CCDResult3 = m.CCD_Data[i, 2] == 1 ? "OK" : (m.CCD_Data[i, 2] == 0 ? "NG" : "缺图");
                            m.CCDResult4 = m.CCD_Data[i, 3] == 1 ? "OK" : (m.CCD_Data[i, 3] == 0 ? "NG" : "缺图");
                            m.CCDResult5 = m.CCD_Data[i, 4] == 1 ? "OK" : (m.CCD_Data[i, 4] == 0 ? "NG" : "缺图");
                            m.CCDResult6 = m.CCD_Data[i, 5] == 1 ? "OK" : (m.CCD_Data[i, 5] == 0 ? "NG" : "缺图");
                            m.CCDResult7 = m.CCD_Data[i, 6] == 1 ? "OK" : (m.CCD_Data[i, 6] == 0 ? "NG" : "缺图");
                            m.CCDResult8 = m.CCD_Data[i, 7] == 1 ? "OK" : (m.CCD_Data[i, 7] == 0 ? "NG" : "缺图");
                            m.CCDResult9 = m.CCD_Data[i, 8] == 1 ? "OK" : (m.CCD_Data[i, 8] == 0 ? "NG" : "缺图");
                            m.CCDResult10 = m.CCD_Data[i, 9] == 1 ? "OK" : (m.CCD_Data[i, 9] == 0 ? "NG" : "缺图");
                            m.CCDResult11 = m.CCD_Data[i, 10] == 1 ? "OK" : (m.CCD_Data[i, 10] == 0 ? "NG" : "缺图");
                            m.CCDResult12 = m.CCD_Data[i, 11] == 1 ? "OK" : (m.CCD_Data[i, 11] == 0 ? "NG" : "缺图");
                            m.CCDResult13 = m.CCD_Data[i, 12] == 1 ? "OK" : (m.CCD_Data[i, 12] == 0 ? "NG" : "缺图");
                            m.CCDResult14 = m.CCD_Data[i, 13] == 1 ? "OK" : (m.CCD_Data[i, 13] == 0 ? "NG" : "缺图");
                            m.CCDResult15 = m.CCD_Data[i, 14] == 1 ? "OK" : (m.CCD_Data[i, 14] == 0 ? "NG" : "缺图");
                            m.CCDResult16 = m.CCD_Data[i, 15] == 1 ? "OK" : (m.CCD_Data[i, 15] == 0 ? "NG" : "缺图");
                            m.CCDResult17 = m.CCD_Data[i, 16] == 1 ? "OK" : (m.CCD_Data[i, 16] == 0 ? "NG" : "缺图");
                            m.CCDResult18 = m.CCD_Data[i, 17] == 1 ? "OK" : (m.CCD_Data[i, 17] == 0 ? "NG" : "缺图");
                            m.CCDResult19 = m.CCD_Data[i, 18] == 1 ? "OK" : (m.CCD_Data[i, 18] == 0 ? "NG" : "缺图");
                            m.CCDResult20 = m.CCD_Data[i, 19] == 1 ? "OK" : (m.CCD_Data[i, 19] == 0 ? "NG" : "缺图");
                            m.CCDResult21 = m.CCD_Data[i, 20] == 1 ? "OK" : (m.CCD_Data[i, 20] == 0 ? "NG" : "缺图");
                            m.CCDResult22 = m.CCD_Data[i, 21] == 1 ? "OK" : (m.CCD_Data[i, 21] == 0 ? "NG" : "缺图");
                            m.CCDResult23 = m.CCD_Data[i, 22] == 1 ? "OK" : (m.CCD_Data[i, 22] == 0 ? "NG" : "缺图");
                            m.CCDResult24 = m.CCD_Data[i, 23] == 1 ? "OK" : (m.CCD_Data[i, 23] == 0 ? "NG" : "缺图");
                            m.CCDResult25 = m.CCD_Data[i, 24] == 1 ? "OK" : (m.CCD_Data[i, 24] == 0 ? "NG" : "缺图");
                            m.CCDResult26 = m.CCD_Data[i, 25] == 1 ? "OK" : (m.CCD_Data[i, 25] == 0 ? "NG" : "缺图");
                            m.CCDResult27 = m.CCD_Data[i, 26] == 1 ? "OK" : (m.CCD_Data[i, 26] == 0 ? "NG" : "缺图");
                            #endregion
                            m.CSBYHASCANNINGTIME = m.ScanTime[1];
                            m.CSBYHPROCESSNAME = "外观检测";
                            m.CSBYHSCHEDULE = CommonMethods.strClass;
                            m.CSBYHINSTATIONTIME = m.ScanTime[0];
                            m.CSBYHOUTSTATIONTIME = m.ScanTime[1];
                            m.TestTime = m.ScanTime[1];
                            m.MaterialCode = CommonMethods.mesConfig.MaterialCode;
                            m.ChannelNo = i + 1;
                            #endregion

                            #endregion
                        }
                        else
                        {
                            CommonMethods.AddDataMonitorLog(0, "出站下料工位A有料标志为0".Translated() + "通道号".Translated() + $"：{i}");
                        }

                        #region 数据保存
                        

                        list.Add(m);
                        #endregion
                    }
                    #endregion

                    #region 数据上传
                    if (list.Count > 0)
                    {
                        if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
                        {
                            //var (success, mesage, mesResType) = await CommonMethods.hbgMes.ManyCellOutStationAsync(CommonMethods.mesConfig.ProductOutStation, CommonMethods.mesConfig.siteCode, CommonMethods.mesConfig.lineCode,
                            //             CommonMethods.mesConfig.equipNum, CommonMethods.mesConfig.MaterialCode, CommonMethods.mesConfig.ModelName, CommonMethods.mesConfig.mesUserName, list, 1, CommonMethods.mesConfig.materialLotCodeLocator);
                            // 初始化结果收集列表
                            var tempMesMessages = new List<string>();
                            var tempMesResTypes = new List<MesResType>();
                            var tempFlags = new List<string>();
                            foreach (var item in list)
                            {
                                // 创建单个电池的列表
                                var singleBatteryList = new List<BGearEntity> { item };

                                // 调用MES接口（每次只传一个电池）
                                var (success, mesage, mesResType) = await CommonMethods.hbgMes.ManyCellOutStationAsync(
                                    CommonMethods.mesConfig.ProductOutStation,
                                    CommonMethods.mesConfig.siteCode,
                                    CommonMethods.mesConfig.lineCode,
                                    CommonMethods.mesConfig.equipNum,
                                    CommonMethods.mesConfig.MaterialCode,
                                    CommonMethods.mesConfig.ModelName,
                                    CommonMethods.mesConfig.mesUserName,
                                    singleBatteryList,
                                    1,
                                    CommonMethods.mesConfig.materialLotCodeLocator);
                                if (success)
                                {
                                    // 收集成功结果
                                    tempMesMessages.AddRange(mesage);
                                    tempMesResTypes.AddRange(mesResType);
                                    tempFlags.Add("1");
                                }
                                else
                                {
                                    // 收集失败结果
                                    tempMesMessages.AddRange(mesage);
                                    tempMesResTypes.AddRange(mesResType);
                                    tempFlags.Add("2");

                                    // 记录失败状态
                                    listRes = GetList<short>(3, 3);
                                    listRemark = GetList<string>(3, "");
                                    if (mesage.Count > 0 && mesage[0].Contains("一个或多个错误"))
                                    {
                                        CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short); // 反馈PLC结果
                                    }
                                }
                            }
                            // 将收集的结果赋给主列表
                            listMesMesage = tempMesMessages;
                            listMesResType = tempMesResTypes;
                            listFlag = tempFlags;

                        }
                        else
                        {
                            listRes = GetList<short>(3, 3);
                            listRemark = GetList<string>(3, "MES断连".Translated() + ",");
                            listFlag = GetList<string>(3, "2");

                            CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short);//反馈MES结果
                        }

                    }
                    //结果数据上传
                    UpProducResultParam(list);
                    #endregion

                    #region 数据组合
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (String.IsNullOrEmpty(list[i].BarCode) || list[i].BarCode.Trim() == "ERROR" || !IsAlphaNumeric(list[i].BarCode))
                        {
                            listRes[i] = 2;
                            listResult[i] = "NG";
                            list[i].Info = "电芯码不良".Translated();
                            list[i].CSBYHOUTSTATIONJUDGMENTRESULT = listResult[i];
                        }
                        else
                        {
                            string strErr = "";
                            //short a = (short)GetResult(ccdTestResult, ref strErr);
                            var judementResult = JudgmentWGJResult(1, list[i].CCD_Data, i);
                            short a = judementResult.Item1;
                            listResult[i] = a == 1 ? "OK" : "NG";
                            list[i].Info = judementResult.Item3;//strErr;
                            list[i].CSBYHOUTSTATIONJUDGMENTRESULT = listResult[i];
                            listRemark[i] += $"{judementResult.Item2}";
                            // 本地判断OK，MES判断OK
                            if (listResult[i] == "OK" && listMesResType[i] == MesResType.D)
                            {
                                listResult[i] += ",MES OK";
                                list[i].Info = "良品".Translated();
                                listRes[i] = 1;
                            }
                            // 本地判断OK，MES判断NG
                            else if (listResult[i] == "OK" && listMesResType[i] != MesResType.D)
                            {
                                switch (listMesResType[i])
                                {
                                    case MesResType.A: // 停线，设备报警停机
                                        listResult[i] += ",MES NG";
                                        listRemark[i] += $"A,{listMesMesage[i]}";
                                        listRes[i] = 3;//10
                                        break;
                                    case MesResType.B: // MES不良
                                        listResult[i] += ",MES NG";
                                        listRemark[i] += $"B,{listMesMesage[i]}";
                                        listRes[i] = 3;//9
                                        break;
                                    case MesResType.C: // 警示
                                        listResult[i] += ",MES OK"; // MES认为是可以当成良品流下去的
                                        listRemark[i] += $"Alarm:{listMesMesage[i]}";
                                        listRes[i] = 1;
                                        break;
                                    case MesResType.D: // 条码上传OK
                                        listResult[i] += ",MES OK";
                                        listRemark[i] += $"D,{listMesMesage[i]}";
                                        listRes[i] = 1;
                                        break;
                                    default:
                                        listResult[i] += ",MES NG";
                                        listRemark[i] += $"{listMesMesage[i]}";
                                        listRes[i] = 3;//9
                                        break;
                                }
                            }
                            // 本地判断NG，MES判断OK
                            else if (listResult[i] == "NG" && listMesResType[i] == MesResType.D)
                            {
                                listResult[i] += ",MES OK";
                                listRemark[i] += $"D,{listMesMesage[i]}";
                                listRes[i] = 1;
                            }
                            // 本地判断NG，MES判断NG
                            else if (listResult[i] == "NG" && listMesResType[i] != MesResType.D)
                            {
                                listResult[i] += ",MES NG";
                                listRemark[i] += $"{listMesResType[i].ToString()},{listMesMesage[i]}";
                                listRes[i] = 3;//9
                            }
                            // 其他情况
                            else
                            {
                                listResult[i] += ",MES NG";
                                listRemark[i] += listMesMesage[i];
                                listRes[i] = 3;//9
                            }
                        }
                        list[i].Result = listResult[i].TrimStart(',').TrimEnd(',');
                        list[i].Remark = listRemark[i].TrimStart(',').TrimEnd(',');
                        list[i].Flag = listFlag[i];
                        list[i].PlcResult = listRes[i];
                    }
                    #endregion

                    #region 判断电芯是否属于复投
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (!(String.IsNullOrEmpty(list[i].BarCode) || list[i].BarCode.Trim() == "ERROR" || !IsAlphaNumeric(list[i].BarCode)))
                        {
                            List<BGearEntity> listBGearEntity = CommonMethods.db.QuerySqlList<BGearEntity>(CommonMethods.dBSQL.GetOutCcdResultSql(list[i].BarCode));
                            if (listBGearEntity != null && listBGearEntity.Count > 0)
                            {
                                // 属于复投电芯（上一次CCD检测结果NG）
                                // 本次CCD检测结果NG
                                if (!GetWGJCcdResult(list[i])) { listRes[i] = 4; }
                                list[i].RethrowNum = listBGearEntity.Count ; // 复投次数  
                            }
                        }
                    }
                    #endregion

                    #region 数据反馈&上传
                    if (pf.IsFeedbackPlc)
                    {
                        //CommonMethods.plcDevices[pf.PlcNum - 1].WriteInt16(pf.VarList[1].VarAddress, (short)listRes); // 反馈PLC结果
                        //写入·结果反馈
                        JYResult result1 = CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue(pf.VarList[1].VarAddress, listRes.ToArray(), PLC.DataType.ArrShort);//判断结果写入PLC
                        if (result1 != null)
                        {
                            string strres = "出站A工位发送给PLC".Translated() + $",[{pf.VarList[1].VarAddress}]:{string.Join(",", listRes)}";
                            CommonMethods.AddDataMonitorLog(0, strres);
                        }
                    }

                    CommonMethods.plcDevices[pf.PlcNum - 1].WriteInt16(pf.VarList[0].VarAddress, (short)0); // 置位0
                    LogHelper.Instance.WriteLog($"A出站发送信息给PLC：{string.Join(",", listRes)}");

                    // 数据存储 - 异步处理
                    SaveBlankingData(list);

                    //if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
                    //{
                    //    UpProducResultParam(list);
                    //}

                    #endregion

                }
                catch (Exception ex)
                {
                    LogHelper.Instance.WriteError($"电芯出站A线程数据处理：{ex}", "SysErrorLog");
                }

                sw.Stop();

                // 输出上料数据处理耗时：
                CommonMethods.AddDataMonitorLog(0, "电芯出站A共耗时".Translated() + $"：{sw.Elapsed.TotalMilliseconds}ms");
            }
        }
        /// <summary>
        /// 电芯出站B
        /// </summary>
        /// <param name="bArrays"></param>
        /// <param name="plcModel"></param>
        //private async Task BlankingStationB(JYResult<byte[]> bArrays, object plcModel)
        //{
        //    PlcGroup pf = plcModel as PlcGroup;
        //    var sw = new Stopwatch();
        //    if (bArrays.IsSuccess && bArrays.Content != null)
        //    {
        //        try
        //        {

        //            #region 初始化数据
        //            sw.Start();
        //            List<BGearEntity> list = new List<BGearEntity>();
        //            List<short> listRes = GetList<short>(8, 2);//默认为1，良品
        //            List<bool> listMark = GetList<bool>(8, false);//有料标志
        //            List<string> listCode = GetList<string>(8, "");//电芯码
        //            List<string> listRemark = GetList<string>(8, "");//备注
        //            List<string> listFlag = GetList<string>(8, "0");//是否上传标志
        //            List<string> listResult = GetList<string>(8, "OK");//结果
        //            List<string> listMesMesage = GetList<string>(8, "");//mesMesage
        //            List<MesResType> listMesResType = GetList<MesResType>(8, MesResType.B);//mesType

        //            //ushort listRes = 1; // 默认为1，良品
        //            string lst_RFIDCodes = ""; // 托杯码
        //            string lst_BarCodes = ""; // 条码

        //            string windSpeed = "";// 风速
        //            string ccdFaceTestDeviceNum1;// 端面检测设备号1
        //            string ccdFaceTestDeviceNum2;// 端面检测设备号2
        //            string ccdFaceTestDeviceNum3;// 端面检测设备号3
        //            string ccdFaceTestDeviceNum4;// 端面检测设备号4
        //            string ccdCylinderTestDeviceNum1;// 柱面检测设备号1
        //            string ccdCylinderTestDeviceNum2;// 柱面检测设备号2
        //            string ccdCylinderTestDeviceNum3;// 柱面检测设备号3

        //            //int ccdPosFaceTestResult = 0; //正极端面检测结果
        //            //int ccdNegFaceTestResult = 0; //负极端面检测结果
        //            //int ccdBeforeCoatedCylinderTestResult = 0; //包膜前圆柱面检测结果
        //            //int ccdPosCylinderTestResult = 0;//正极柱检测结果
        //            //int ccdNegCylinderTestResult = 0;//负极柱检测结果

        //            int ccdNegativeTerminalWeldingZone2DInspectionResult = 0; //负极焊接区2D检测结果
        //            int ccdNegativeTerminalWeldingZone2DInspectionNGReasons = 0; //负极焊接区2D检测NG原因（脏污）
        //            int ccdNegativeTerminalWeldingZone2DInspectionNGReasons1 = 0; //负极焊接区2D检测NG原因（划伤）
        //            int ccdNegativeTerminalWeldingZone2DInspectionNGReasons2 = 0; //负极焊接区2D检测NG原因（凹点）

        //            int ccdCoverPlate2DInspectionResult = 0; //盖板2D检测结果
        //            int ccdCoverPlate2DInspectionNGReasons = 0; //盖板2D检测NG原因（脏污）
        //            int ccdCoverPlate2DInspectionNGReasons1 = 0; //盖板2D检测NG原因（划伤）
        //            int ccdCoverPlate2DInspectionNGReasons2 = 0; //盖板2D检测NG原因（凹点）


        //            int ccdNegativeTerminalWeldingZone25DInspectionResult = 0; //负极焊接区2.5D检测结果
        //            int ccdNegativeTerminalWeldingZone25DInspectionNGReasons = 0; //负极焊接区2.5D检测NG原因（脏污）
        //            int ccdNegativeTerminalWeldingZone25DInspectionNGReasons1 = 0; //负极焊接区2.5D检测NG原因（划伤）
        //            int ccdNegativeTerminalWeldingZone25DInspectionNGReasons2 = 0; //负极焊接区2.5D检测NG原因（凹点）


        //            int ccdCoverPlate25DInspectionResult = 0; //盖板2.5D检测结果
        //            int ccdCoverPlate25DInspectionNGReasons = 0; //盖板2.5D检测NG原因（脏污）
        //            int ccdCoverPlate25DInspectionNGReasons1 = 0; //盖板2.5D检测NG原因（划伤）
        //            int ccdCoverPlate25DInspectionNGReasons2 = 0; //盖板2.5D检测NG原因（凹点）


        //            int ccdTerminalPost2DInspectionResult = 0; //极柱2D检测结果
        //            int ccdTerminalPost2DInspectionNGReasons = 0; //极柱2D检测NG原因（脏污）
        //            int ccdTerminalPost2DInspectionNGReasons1 = 0; //极柱2D检测NG原因（划伤）
        //            int ccdTerminalPost2DInspectionNGReasons2 = 0; //极柱2D检测NG原因（凹点）
        //            int ccdTerminalPost2DInspectionNGReasons3 = 0; //极柱2D检测NG原因（残缺）


        //            int ccdTerminalPost3DInspectionResult = 0; //极柱3D检测结果
        //            int ccdTerminalPost3DInspectionNGReasons = 0; //极柱3D检测NG原因（脏污）
        //            int ccdTerminalPost3DInspectionNGReasons1 = 0; //极柱3D检测NG原因（划伤）
        //            int ccdTerminalPost3DInspectionNGReasons2 = 0; //极柱3D检测NG原因（凹点）
        //            int ccdTerminalPost3DInspectionNGReasons3 = 0; //极柱3D检测NG原因（残缺）

        //            int ccdSealingNail2DInspectionResult = 0; //密封钉2D检测结果
        //            int ccdSealingNail2DInspectionNGReasons = 0; //密封钉2D检测NG原因（铝钉焊接）

        //            int ccdSealingNail3DInspectionResult = 0; //密封钉3D检测结果
        //            int ccdSealingNail3DInspectionNGReasons = 0; //密封钉3D检测NG原因（铝钉焊接）

        //            int ccdTopFillet25DInspectionResult = 0; //上部R角2.5D检测结果
        //            int ccdTopFillet25DInspectionNGReasons = 0; //上部R角2.5D检测NG原因（凹点）

        //            int ccdBottomFillet25DInspectionResult = 0; //底部R角2.5D检测结果
        //            int ccdBottomFillet25DInspectionNGReasons = 0; //底部R角2.5D检测NG原因（凹点）

        //            int ccdCylindricalSurface25DInspectionResult = 0; //柱面2.5D检测结果
        //            int ccdCylindricalSurface25DInspectionNGReasons = 0; //柱面2.5D检测NG原因（生锈）
        //            int ccdCylindricalSurface25DInspectionNGReasons1 = 0; //柱面2.5D检测NG原因（划伤）
        //            int ccdCylindricalSurface25DInspectionNGReasons2 = 0; //柱面2.5D检测NG原因（凹点）
        //            int ccdCylindricalSurface25DInspectionNGReasons3 = 0; //柱面2.5D检测NG原因（模糊）


        //            int ccdCylindricalSurface3DInspectionResult = 0; //柱面3D检测结果
        //            int ccdCylindricalSurface3DInspectionNGReasons = 0; //柱面3D检测NG原因（生锈）
        //            int ccdCylindricalSurface3DInspectionNGReasons1 = 0; //柱面3D检测NG原因（划伤）
        //            int ccdCylindricalSurface3DInspectionNGReasons2 = 0; //柱面3D检测NG原因（凹点）
        //            int ccdCylindricalSurface3DInspectionNGReasons3 = 0; //柱面3D检测NG原因（模糊）

        //            int[] ccdTestResult = new int[12];//ccd检测结果

        //            string result = "";//总结果
        //            string info = "";//NG详情

        //            #endregion

        //            #region 数据解析
        //            byte[] bytes = bArrays.Content.ByteReverse();

        //            //有料标志
        //            for (int i = 0; i < listMark.Count; i++)
        //            {
        //                listMark[i] = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2)) == 1 ? true : false;// 从D6021开始
        //                if (listMark[i])
        //                {
        //                    #region 数据读取
        //                    //条码长度
        //                    int codeLength = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (20 * 2));// 从D6041开始
        //                    if (codeLength > 0)
        //                    {
        //                        //条码
        //                        listCode[i] = StringLib.GetStringFromByteArrayByEncoding(bytes, (i * 50) + (79 * 2), codeLength, System.Text.Encoding.ASCII).// 从D4100开始
        //                           Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim();
        //                    }
        //                    else { listCode[i] = "ERROR"; }

        //                    #region 旧
        //                    //windSpeed = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 2) + (579 * 2), DataFormat.CDAB).ToString("f3"); // 风速 D6600 579
        //                    //ccdFaceTestDeviceNum1 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (595 * 2), DataFormat.CDAB).ToString("f3"); // 端面检测设备号1 D6616 595
        //                    //ccdFaceTestDeviceNum2 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (597 * 2), DataFormat.CDAB).ToString("f3"); // 端面检测设备号2 D6618 597
        //                    //ccdFaceTestDeviceNum3 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (599 * 2), DataFormat.CDAB).ToString("f3"); // 端面检测设备号3 D6620 599
        //                    //ccdFaceTestDeviceNum4 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (601 * 2), DataFormat.CDAB).ToString("f3"); // 端面检测设备号4 D6622 601

        //                    //ccdCylinderTestDeviceNum1 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (659 * 2), DataFormat.CDAB).ToString("f3"); // 柱面检测设备号1 D6680 659
        //                    //ccdCylinderTestDeviceNum2 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (661 * 2), DataFormat.CDAB).ToString("f3"); // 柱面检测设备号2 D6682 661
        //                    //ccdCylinderTestDeviceNum3 = FloatLib.GetFloatFromByteArray(bArrays.Content, (i * 8) * 2 + (663 * 2), DataFormat.CDAB).ToString("f3"); // 柱面检测设备号3 D6684 663

        //                    //ccdPosFaceTestResult = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (707 * 2));// 正极端面检测结果 D6728 707
        //                    //ccdNegFaceTestResult = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (715 * 2));// 负极端面检测结果 D6736 715
        //                    //ccdBeforeCoatedCylinderTestResult = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (723 * 2));// 包膜前圆柱面检测结果 D6744 723
        //                    //ccdPosCylinderTestResult = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (731 * 2));// 正极柱检测结果 D6752 731
        //                    //ccdNegCylinderTestResult = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (739 * 2));// 负极柱检测结果 D6760 739

        //                    //result = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (747 * 2)).ToString("f3");// 总结果 D6768 747
        //                    //info = ShortLib.GetShortFromByteArray(bArrays.Content, (i * 2) + (755 * 2)).ToString("f3");// NG详情 D6776 755
        //                    #endregion

        //                    windSpeed = GetValueFromByteArray(bArrays.Content, "windSpeed", i == 0 ? 0 : (int)Math.Pow(2, i + 1)); // 风速 D6600 579
        //                    ccdFaceTestDeviceNum1 = GetValueFromByteArray(bArrays.Content, "ccdFaceTestDeviceNum1", (i * 8) * 2);  // 端面检测设备号1 D6616 595
        //                    ccdFaceTestDeviceNum2 = GetValueFromByteArray(bArrays.Content, "ccdFaceTestDeviceNum2", (i * 8) * 2);  // 端面检测设备号2 D6618 597
        //                    ccdFaceTestDeviceNum3 = GetValueFromByteArray(bArrays.Content, "ccdFaceTestDeviceNum3", (i * 8) * 2);  // 端面检测设备号3 D6620 599
        //                    ccdFaceTestDeviceNum4 = GetValueFromByteArray(bArrays.Content, "ccdFaceTestDeviceNum4", (i * 8) * 2);  // 端面检测设备号4 D6622 601

        //                    ccdCylinderTestDeviceNum1 = GetValueFromByteArray(bArrays.Content, "ccdCylinderTestDeviceNum1", (i * 8) * 2); // 柱面检测设备号1 D6680 659
        //                    ccdCylinderTestDeviceNum2 = GetValueFromByteArray(bArrays.Content, "ccdCylinderTestDeviceNum2", (i * 8) * 2); // 柱面检测设备号2 D6682 661
        //                    ccdCylinderTestDeviceNum3 = GetValueFromByteArray(bArrays.Content, "ccdCylinderTestDeviceNum3", (i * 8) * 2); // 柱面检测设备号3 D6684 663

        //                    //ccdPosFaceTestResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdPosFaceTestResult", (i * 2)));// 正极端面检测结果 D6728 707
        //                    //ccdNegFaceTestResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegFaceTestResult", (i * 2)));// 负极端面检测结果 D6736 715
        //                    //ccdBeforeCoatedCylinderTestResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdBeforeCoatedCylinderTestResult", (i * 2)));// 包膜前圆柱面检测结果 D6744 723
        //                    //ccdPosCylinderTestResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdPosCylinderTestResult", (i * 2)));// 正极柱检测结果 D6752 731
        //                    //ccdNegCylinderTestResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegCylinderTestResult", (i * 2)));// 负极柱检测结果 D6760 739

        //                    ccdNegativeTerminalWeldingZone2DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone2DInspectionResult", (i * 2))); // 负极焊接区2D检测结果
        //                    ccdNegativeTerminalWeldingZone2DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone2DInspectionNGReasons", (i * 2))); // 负极焊接区2D检测NG原因
        //                    ccdNegativeTerminalWeldingZone2DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone2DInspectionNGReasons1", (i * 2))); // 负极焊接区2D检测NG原因
        //                    ccdNegativeTerminalWeldingZone2DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone2DInspectionNGReasons2", (i * 2))); // 负极焊接区2D检测NG原因

        //                    ccdCoverPlate2DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate2DInspectionResult", (i * 2))); // 盖板2D检测结果
        //                    ccdCoverPlate2DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate2DInspectionNGReasons", (i * 2))); // 盖板2D检测NG原因
        //                    ccdCoverPlate2DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate2DInspectionNGReasons1", (i * 2))); // 盖板2D检测NG原因
        //                    ccdCoverPlate2DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate2DInspectionNGReasons2", (i * 2))); // 盖板2D检测NG原因

        //                    ccdNegativeTerminalWeldingZone25DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone25DInspectionResult", (i * 2))); // 负极焊接区2.5D检测结果
        //                    ccdNegativeTerminalWeldingZone25DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone25DInspectionNGReasons", (i * 2))); // 负极焊接区2.5D检测NG原因
        //                    ccdNegativeTerminalWeldingZone25DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone25DInspectionNGReasons1", (i * 2))); // 负极焊接区2.5D检测NG原因
        //                    ccdNegativeTerminalWeldingZone25DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdNegativeTerminalWeldingZone25DInspectionNGReasons2", (i * 2))); // 负极焊接区2.5D检测NG原因

        //                    ccdCoverPlate25DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate25DInspectionResult", (i * 2))); // 盖板2.5D检测结果
        //                    ccdCoverPlate25DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate25DInspectionNGReasons", (i * 2))); // 盖板2.5D检测NG原因
        //                    ccdCoverPlate25DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate25DInspectionNGReasons1", (i * 2))); // 盖板2.5D检测NG原因
        //                    ccdCoverPlate25DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCoverPlate25DInspectionNGReasons2", (i * 2))); // 盖板2.5D检测NG原因

        //                    ccdTerminalPost2DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost2DInspectionResult", (i * 2))); // 极柱2D检测结果
        //                    ccdTerminalPost2DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost2DInspectionNGReasons", (i * 2))); // 极柱2D检测NG原因
        //                    ccdTerminalPost2DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost2DInspectionNGReasons1", (i * 2))); // 极柱2D检测NG原因
        //                    ccdTerminalPost2DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost2DInspectionNGReasons2", (i * 2))); // 极柱2D检测NG原因
        //                    ccdTerminalPost2DInspectionNGReasons3 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost2DInspectionNGReasons3", (i * 2))); // 极柱2D检测NG原因

        //                    ccdTerminalPost3DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost3DInspectionResult", (i * 2))); // 极柱3D检测结果
        //                    ccdTerminalPost3DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost3DInspectionNGReasons", (i * 2))); // 极柱3D检测NG原因
        //                    ccdTerminalPost3DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost3DInspectionNGReasons1", (i * 2))); // 极柱3D检测NG原因
        //                    ccdTerminalPost3DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost3DInspectionNGReasons2", (i * 2))); // 极柱3D检测NG原因
        //                    ccdTerminalPost3DInspectionNGReasons3 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTerminalPost3DInspectionNGReasons3", (i * 2))); // 极柱3D检测NG原因

        //                    ccdSealingNail2DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdSealingNail2DInspectionResult", (i * 2))); // 密封钉2D检测结果
        //                    ccdSealingNail2DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdSealingNail2DInspectionNGReasons", (i * 2))); // 密封钉2D检测NG原因

        //                    ccdSealingNail3DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdSealingNail3DInspectionResult", (i * 2))); // 密封钉3D检测结果
        //                    ccdSealingNail3DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdSealingNail3DInspectionNGReasons", (i * 2))); // 密封钉3D检测NG原因

        //                    ccdTopFillet25DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTopFillet25DInspectionResult", (i * 2))); // 上部R角2.5D检测结果
        //                    ccdTopFillet25DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdTopFillet25DInspectionNGReasons", (i * 2))); // 上部R角2.5D检测NG原因

        //                    ccdBottomFillet25DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdBottomFillet25DInspectionResult", (i * 2))); // 底部R角2.5D检测结果
        //                    ccdBottomFillet25DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdBottomFillet25DInspectionNGReasons", (i * 2))); // 底部R角2.5D检测NG原因

        //                    ccdCylindricalSurface25DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface25DInspectionResult", (i * 2))); // 柱面2.5D检测结果
        //                    ccdCylindricalSurface25DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface25DInspectionNGReasons", (i * 2))); // 柱面2.5D检测NG原因
        //                    ccdCylindricalSurface25DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface25DInspectionNGReasons1", (i * 2))); // 柱面2.5D检测NG原因
        //                    ccdCylindricalSurface25DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface25DInspectionNGReasons2", (i * 2))); // 柱面2.5D检测NG原因
        //                    ccdCylindricalSurface25DInspectionNGReasons3 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface25DInspectionNGReasons3", (i * 2))); // 柱面2.5D检测NG原因

        //                    ccdCylindricalSurface3DInspectionResult = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface3DInspectionResult", (i * 2))); // 柱面3D检测结果
        //                    ccdCylindricalSurface3DInspectionNGReasons = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface3DInspectionNGReasons", (i * 2))); // 柱面3D检测NG原因
        //                    ccdCylindricalSurface3DInspectionNGReasons1 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface3DInspectionNGReasons1", (i * 2))); // 柱面3D检测NG原因
        //                    ccdCylindricalSurface3DInspectionNGReasons2 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface3DInspectionNGReasons2", (i * 2))); // 柱面3D检测NG原因
        //                    ccdCylindricalSurface3DInspectionNGReasons3 = int.Parse(GetValueFromByteArray(bArrays.Content, "ccdCylindricalSurface3DInspectionNGReasons3", (i * 2))); // 柱面3D检测NG原因


        //                    ccdTestResult[0] = ccdNegativeTerminalWeldingZone2DInspectionResult;
        //                    ccdTestResult[1] = ccdCoverPlate2DInspectionResult;
        //                    ccdTestResult[2] = ccdNegativeTerminalWeldingZone25DInspectionResult;
        //                    ccdTestResult[3] = ccdCoverPlate25DInspectionResult;
        //                    ccdTestResult[4] = ccdTerminalPost2DInspectionResult;
        //                    ccdTestResult[5] = ccdTerminalPost3DInspectionResult;
        //                    ccdTestResult[6] = ccdSealingNail2DInspectionResult;
        //                    ccdTestResult[7] = ccdSealingNail3DInspectionResult;
        //                    ccdTestResult[8] = ccdTopFillet25DInspectionResult;
        //                    ccdTestResult[9] = ccdBottomFillet25DInspectionResult;
        //                    ccdTestResult[10] = ccdCylindricalSurface25DInspectionResult;
        //                    ccdTestResult[11] = ccdCylindricalSurface3DInspectionResult;

        //                    //ccdTestResult[0] = ccdPosFaceTestResult;
        //                    //ccdTestResult[1] = ccdNegFaceTestResult;
        //                    //ccdTestResult[2] = ccdBeforeCoatedCylinderTestResult;
        //                    //ccdTestResult[3] = ccdPosCylinderTestResult;
        //                    //ccdTestResult[4] = ccdNegCylinderTestResult;

        //                    result = GetValueFromByteArray(bArrays.Content, "result", (i * 2));// 总结果 D6768 747
        //                    info = GetValueFromByteArray(bArrays.Content, "info", (i * 2));// NG详情 D6776 755

        //                    lst_RFIDCodes = "";//StringLib.GetStringFromByteArrayByEncoding(bytes, 0, 39, Encoding.ASCII).Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim(); // RFID D3200-3219
        //                    lst_BarCodes = listCode[i];

        //                    #endregion
        //                }
        //                else
        //                {
        //                    CommonMethods.AddDataMonitorLog(0, "出站下料工位B有料标志为0".Translated() + "通道号".Translated() + $"：{i}");
        //                }

        //                #region 数据保存
        //                BGearEntity m = new BGearEntity
        //                {
        //                    ChannelNo = (i + 1).ToString(),
        //                    TestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
        //                    RFID = lst_RFIDCodes,
        //                    BarCode = lst_BarCodes,
        //                    WindSpeed = windSpeed,
        //                    WindDeviceNum = "B",
        //                    CCDFaceTestDeviceNum1 = "B",
        //                    CCDFaceTestDeviceNum2 = "B",
        //                    CCDFaceTestDeviceNum3 = "B",
        //                    CCDFaceTestDeviceNum4 = "B",

        //                    CCDCylinderTestDeviceNum1 = "B",
        //                    CCDCylinderTestDeviceNum2 = "B",
        //                    CCDCylinderTestDeviceNum3 = "B",

        //                    //CCDPosFaceTestResult = ccdPosFaceTestResult == 1 ? "OK" : "NG",
        //                    //CCDNegFaceTestResult = ccdNegFaceTestResult == 1 ? "OK" : "NG",
        //                    //CCDBeforeCoatedCylinderTestResult = ccdBeforeCoatedCylinderTestResult == 1 ? "OK" : "NG",
        //                    //CCDPosCylinderTestResult = ccdPosCylinderTestResult == 1 ? "OK" : "NG",
        //                    //CCDNegCylinderTestResult = ccdNegCylinderTestResult == 1 ? "OK" : "NG",

        //                    CCDNegativeTerminalWeldingZone2DInspectionResult = ccdNegativeTerminalWeldingZone2DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDNegativeTerminalWeldingZone2DInspectionNGReasons = CombineNGReasons
        //                                                                         (GetNGReasons(ccdNegativeTerminalWeldingZone2DInspectionNGReasons, "UI20801"),
        //                                                                          GetNGReasons(ccdNegativeTerminalWeldingZone2DInspectionNGReasons1, "UI21301"),
        //                                                                          GetNGReasons(ccdNegativeTerminalWeldingZone2DInspectionNGReasons2, "UI127")),
        //                    CCDCoverPlate2DInspectionResult = ccdCoverPlate2DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDCoverPlate2DInspectionNGReasons = CombineNGReasons
        //                                                        (GetNGReasons(ccdCoverPlate2DInspectionNGReasons, "UI20801"),
        //                                                         GetNGReasons(ccdCoverPlate2DInspectionNGReasons1, "UI21301"),
        //                                                         GetNGReasons(ccdCoverPlate2DInspectionNGReasons2, "UI127")),
        //                    CCDNegativeTerminalWeldingZone25DInspectionResult = ccdNegativeTerminalWeldingZone25DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDNegativeTerminalWeldingZone25DInspectionNGReasons = CombineNGReasons
        //                                                                          (GetNGReasons(ccdNegativeTerminalWeldingZone25DInspectionNGReasons, "UI20801"),
        //                                                                           GetNGReasons(ccdNegativeTerminalWeldingZone25DInspectionNGReasons1, "UI21301"),
        //                                                                           GetNGReasons(ccdNegativeTerminalWeldingZone25DInspectionNGReasons2, "UI127")),
        //                    CCDCoverPlate25DInspectionResult = ccdCoverPlate25DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDCoverPlate25DInspectionNGReasons = CombineNGReasons
        //                                                         (GetNGReasons(ccdCoverPlate25DInspectionNGReasons, "UI20801"),
        //                                                          GetNGReasons(ccdCoverPlate25DInspectionNGReasons1, "UI21301"),
        //                                                          GetNGReasons(ccdCoverPlate25DInspectionNGReasons2, "UI127")),
        //                    CCDTerminalPost2DInspectionResult = ccdTerminalPost2DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDTerminalPost2DInspectionNGReasons = CombineNGReasons
        //                                                         (GetNGReasons(ccdCoverPlate25DInspectionNGReasons, "UI20801"),
        //                                                          GetNGReasons(ccdTerminalPost2DInspectionNGReasons1, "UI21301"),
        //                                                          GetNGReasons(ccdTerminalPost2DInspectionNGReasons2, "UI127"),
        //                                                          GetNGReasons(ccdTerminalPost2DInspectionNGReasons3, "UI125")),
        //                    CCDTerminalPost3DInspectionResult = ccdTerminalPost3DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDTerminalPost3DInspectionNGReasons = CombineNGReasons
        //                                                         (GetNGReasons(ccdTerminalPost3DInspectionNGReasons, "UI20801"),
        //                                                          GetNGReasons(ccdTerminalPost3DInspectionNGReasons1, "UI21301"),
        //                                                          GetNGReasons(ccdTerminalPost3DInspectionNGReasons2, "UI127"),
        //                                                          GetNGReasons(ccdTerminalPost3DInspectionNGReasons3, "UI125")),
        //                    CCDSealingNail2DInspectionResult = ccdSealingNail2DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDSealingNail2DInspectionNGReasons = "",
        //                    CCDSealingNail3DInspectionResult = ccdSealingNail3DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDSealingNail3DInspectionNGReasons = "",
        //                    CCDTopFillet25DInspectionResult = ccdTopFillet25DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDTopFillet25DInspectionNGReasons = CombineNGReasons
        //                                                         (GetNGReasons(ccdTopFillet25DInspectionNGReasons, "UI127")),
        //                    CCDBottomFillet25DInspectionResult = ccdBottomFillet25DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDBottomFillet25DInspectionNGReasons = CombineNGReasons
        //                                                         (GetNGReasons(ccdBottomFillet25DInspectionNGReasons, "UI127")),
        //                    CCDCylindricalSurface25DInspectionResult = ccdCylindricalSurface25DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDCylindricalSurface25DInspectionNGReasons = CombineNGReasons
        //                                                                 (GetNGReasons(ccdCylindricalSurface25DInspectionNGReasons, "UI128"),
        //                                                                  GetNGReasons(ccdCylindricalSurface25DInspectionNGReasons1, "UI21301"),
        //                                                                  GetNGReasons(ccdCylindricalSurface25DInspectionNGReasons2, "UI127"),
        //                                                                  GetNGReasons(ccdCylindricalSurface25DInspectionNGReasons3, "UI00404")),
        //                    CCDCylindricalSurface3DInspectionResult = ccdCylindricalSurface3DInspectionResult == 1 ? "OK" : "NG",
        //                    CCDCylindricalSurface3DInspectionNGReasons = CombineNGReasons
        //                                                                 (GetNGReasons(ccdCylindricalSurface3DInspectionNGReasons, "UI128"),
        //                                                                  GetNGReasons(ccdCylindricalSurface3DInspectionNGReasons1, "UI21301"),
        //                                                                  GetNGReasons(ccdCylindricalSurface3DInspectionNGReasons2, "UI127"),
        //                                                                  GetNGReasons(ccdCylindricalSurface3DInspectionNGReasons3, "UI00404")),


        //                    //Flag = "0",
        //                    Flag1 = "2",
        //                    Result = result,
        //                    Info = info,
        //                    MaterialCode = CommonMethods.mesConfig.MaterialCode,
        //                };

        //                list.Add(m);
        //                #endregion
        //            }
        //            #endregion

        //            #region 数据上传
        //            if (list.Count > 0)
        //            {
        //                if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
        //                {
        //                    //var (success, mesage, mesResType) = await CommonMethods.hbgMes.ManyCellOutStationAsync(CommonMethods.mesConfig.ProductOutStation, CommonMethods.mesConfig.siteCode, CommonMethods.mesConfig.lineCode,
        //                    //             CommonMethods.mesConfig.equipNum, CommonMethods.mesConfig.MaterialCode, CommonMethods.mesConfig.ModelName, CommonMethods.mesConfig.mesUserName, list, 1, CommonMethods.mesConfig.materialLotCodeLocator);
        //                    var tempMesMessages = new List<string>();
        //                    var tempMesResTypes = new List<MesResType>();
        //                    var tempFlags = new List<string>();
        //                    foreach (var item in list)
        //                    {
        //                        // 创建单个电池的列表
        //                        var singleBatteryList = new List<BGearEntity> { item };

        //                        // 调用MES接口（每次只传一个电池）
        //                        var (success, mesage, mesResType) = await CommonMethods.hbgMes.ManyCellOutStationAsync(
        //                            CommonMethods.mesConfig.ProductOutStation,
        //                            CommonMethods.mesConfig.siteCode,
        //                            CommonMethods.mesConfig.lineCode,
        //                            CommonMethods.mesConfig.equipNum,
        //                            CommonMethods.mesConfig.MaterialCode,
        //                            CommonMethods.mesConfig.ModelName,
        //                            CommonMethods.mesConfig.mesUserName,
        //                            singleBatteryList,
        //                            1,
        //                            CommonMethods.mesConfig.materialLotCodeLocator);
        //                        if (success)
        //                        {
        //                            // 收集成功结果
        //                            tempMesMessages.AddRange(mesage);
        //                            tempMesResTypes.AddRange(mesResType);
        //                            tempFlags.Add("1");
        //                        }
        //                        else
        //                        {
        //                            // 收集失败结果
        //                            tempMesMessages.AddRange(mesage);
        //                            tempMesResTypes.AddRange(mesResType);
        //                            tempFlags.Add("2");

        //                            // 记录失败状态
        //                            listRes = GetList<short>(8, 3);
        //                            listRemark = GetList<string>(8, "");
        //                            if (mesage.Count > 0 && mesage[0].Contains("一个或多个错误"))
        //                            {
        //                                CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short); // 反馈PLC结果
        //                            }
        //                        }
        //                    }
        //                    // 将收集的结果赋给主列表
        //                    listMesMesage = tempMesMessages;
        //                    listMesResType = tempMesResTypes;
        //                    listFlag = tempFlags;

        //                }
        //                else
        //                {
        //                    listRes = GetList<short>(8, 3);
        //                    listRemark = GetList<string>(8, "MES断连".Translated() + ",");
        //                    listFlag = GetList<string>(8, "2");

        //                    CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue("D80", 1, PLC.DataType.Short);//反馈MES结果
        //                }
        //            }
        //            UpProducResultParam(list);
        //            #endregion

        //            #region 数据组合
        //            for (int i = 0; i < list.Count; i++)
        //            {
        //                if (String.IsNullOrEmpty(list[i].BarCode) || list[i].BarCode.Trim() == "ERROR" || !IsAlphaNumeric(list[i].BarCode))
        //                {
        //                    listRes[i] = 2;
        //                    listResult[i] = "NG";
        //                    list[i].Info = "电芯码不良".Translated();
        //                }
        //                else
        //                {
        //                    string strErr = "";
        //                    short a = (short)GetResult(ccdTestResult, ref strErr);
        //                    listResult[i] = a == 12 ? "OK" : "NG";
        //                    list[i].Info = strErr;

        //                    // 本地判断OK，MES判断OK
        //                    if (listResult[i] == "OK" && listMesResType[i] == MesResType.D)
        //                    {
        //                        listResult[i] += ",MES OK";
        //                        list[i].Info = "良品".Translated();
        //                        listRes[i] = 1;
        //                    }
        //                    // 本地判断OK，MES判断NG
        //                    else if (listResult[i] == "OK" && listMesResType[i] != MesResType.D)
        //                    {
        //                        switch (listMesResType[i])
        //                        {
        //                            case MesResType.A: // 停线，设备报警停机
        //                                listResult[i] += ",MES NG";
        //                                listRemark[i] += $"A,{listMesMesage[i]}";
        //                                listRes[i] = 3;//10
        //                                break;
        //                            case MesResType.B: // MES不良
        //                                listResult[i] += ",MES NG";
        //                                listRemark[i] += $"B,{listMesMesage[i]}";
        //                                listRes[i] = 3;//9
        //                                break;
        //                            case MesResType.C: // 警示
        //                                listResult[i] += ",MES OK"; // MES认为是可以当成良品流下去的
        //                                listRemark[i] += $"Alarm:{listMesMesage[i]}";
        //                                listRes[i] = 1;
        //                                break;
        //                            case MesResType.D: // 条码上传OK
        //                                listResult[i] += ",MES OK";
        //                                listRemark[i] += $"D,{listMesMesage[i]}";
        //                                listRes[i] = 1;
        //                                break;
        //                            default:
        //                                listResult[i] += ",MES NG";
        //                                listRemark[i] += $"{listMesMesage[i]}";
        //                                listRes[i] = 3;//9
        //                                break;
        //                        }
        //                    }
        //                    // 本地判断NG，MES判断OK
        //                    else if (listResult[i] == "NG" && listMesResType[i] == MesResType.D)
        //                    {
        //                        listResult[i] += ",MES OK";
        //                        listRemark[i] += $"D,{listMesMesage[i]}";
        //                        listRes[i] = 1;
        //                    }
        //                    // 本地判断NG，MES判断NG
        //                    else if (listResult[i] == "NG" && listMesResType[i] != MesResType.D)
        //                    {
        //                        listResult[i] += ",MES NG";
        //                        listRemark[i] += $"{listMesResType[i].ToString()},{listMesMesage[i]}";
        //                        listRes[i] = 3;//9
        //                    }
        //                    // 其他情况
        //                    else
        //                    {
        //                        listResult[i] += ",MES NG";
        //                        listRemark[i] += listMesMesage[i];
        //                        listRes[i] = 3;//9
        //                    }
        //                }
        //                list[i].Result = listResult[i].TrimStart(',').TrimEnd(',');
        //                list[i].Remark = listRemark[i].TrimStart(',').TrimEnd(',');
        //                list[i].Flag = listFlag[i];
        //            }
        //            #endregion

        //            #region 判断电芯是否属于复投
        //            for (int i = 0; i < list.Count; i++)
        //            {
        //                if (!(String.IsNullOrEmpty(list[i].BarCode) || list[i].BarCode.Trim() == "ERROR" || !IsAlphaNumeric(list[i].BarCode)))
        //                {
        //                    List<BGearEntity> listBGearEntity = CommonMethods.db.QuerySqlList<BGearEntity>(CommonMethods.dBSQL.GetOutCcdResultSql(list[i].BarCode));
        //                    if (listBGearEntity != null && listBGearEntity.Count > 0)
        //                    {
        //                        // 属于复投电芯（上一次CCD检测结果NG）
        //                        // 本次CCD检测结果NG
        //                        if (!GetCcdResult(list[i])) { listRes[i] = 4; }
        //                    }
        //                }
        //            }
        //            #endregion

        //            #region 数据保存&上传
        //            if (pf.IsFeedbackPlc)
        //            {
        //                //CommonMethods.plcDevices[pf.PlcNum - 1].WriteInt16(pf.VarList[1].VarAddress, (short)listRes); // 反馈PLC结果
        //                //写入·结果反馈
        //                JYResult result1 = CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue(pf.VarList[1].VarAddress, listRes.ToArray(), PLC.DataType.ArrShort);//判断结果写入PLC
        //                if (result1 != null)
        //                {
        //                    string strres = "出站A工位发送给PLC".Translated() + $",[{pf.VarList[1].VarAddress}]:{string.Join(",", listRes)}";
        //                    CommonMethods.AddDataMonitorLog(0, strres);
        //                }
        //            }

        //            CommonMethods.plcDevices[pf.PlcNum - 1].WriteInt16(pf.VarList[0].VarAddress, (short)0); // 置位0
        //            LogHelper.Instance.WriteLog($"A出站发送信息给PLC：{string.Join(",", listRes)}");

        //            // 数据存储 - 异步处理
        //            SaveBlankingData(list);

        //            //if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
        //            //{

        //            //}
        //            #endregion

        //        }
        //        catch (Exception ex)
        //        {
        //            LogHelper.Instance.WriteError($"电芯出站B线程数据处理：{ex}", "SysErrorLog");
        //        }

        //        sw.Stop();

        //        // 输出上料数据处理耗时：
        //        CommonMethods.AddDataMonitorLog(0, "电芯出站B共耗时".Translated() + $"：{sw.Elapsed.TotalMilliseconds}ms");
        //    }
        //}


        #region 保存下料数据
        /// <summary>
        /// 保存下料数据到数据
        /// </summary>
        /// <param name="list"></param>
        private async void SaveBlankingData(List<BGearEntity> list)
        {
            //数据的保存
            try
            {
                if (list != null && list.Count > 0)
                {
                    //数据显示
                    bool b = await CommonMethods.db.AddReturnBoolAsync<BGearEntity>(list);

                    //数据显示
                    CommonMethods.ShowBlankingDelegate.Invoke(list);

                    //数据保存本地
                    string strData = string.Empty;//数据字符串，本地保存
                    foreach (BGearEntity m in list)
                    {
                        foreach (var item in m.GetType().GetProperties())
                        {
                            strData += item.GetValue(m) + ",";
                        }
                        strData = strData.TrimEnd(',');
                        BlankingDataSaveLocal(strData);
                    }
                }
                else
                {
                    LogHelper.Instance.WriteError($"电芯出站数据List为空", "SysErrorLog");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError($"电芯出站数据保存异常：{ex}", "SysErrorLog");
            }
        }
        #endregion

        /// <summary>
        /// 电池结果判断
        /// </summary>
        /// <returns></returns>
        private ushort GetResult(int[] res, ref string strErr)
        {
            strErr = "";
            int resNum = 0;

            for (int i = 0; i < res.Length; i++)
            {
                if (i == 0)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "负极焊接区2D检测结果不良".Translated() + ",";
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "负极焊接区2D检测结果未知".Translated() + ",";
                            resNum = resNum + 4;
                            break;
                    }
                }
                else if (i == 1)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "盖板2D检测结果不良".Translated() + ",";
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "盖板2D检测结果未知".Translated() + ",";
                            resNum = resNum + 4;
                            break;
                    }
                }
                else if (i == 2)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "负极焊接区2.5D检测结果不良".Translated() + ",";
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "负极焊接区2.5D检测结果未知".Translated() + ",";
                            resNum = resNum + 4;
                            break;
                    }
                }
                else if (i == 3)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "盖板2.5D检测结果不良".Translated() + ",";
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "盖板2.5D检测结果未知".Translated() + ",";
                            resNum = resNum + 4;
                            break;
                    }
                }
                else if (i == 4)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "极柱2D检测结果不良".Translated();
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "极柱2D检测结果未知".Translated();
                            resNum = resNum + 4;
                            break;
                    }
                }
                else if (i == 5)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "极柱3D检测结果不良".Translated();
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "极柱3D检测结果未知".Translated();
                            resNum = resNum + 4;
                            break;
                    }
                }
                else if (i == 6)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "密封钉2D检测结果不良".Translated();
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "密封钉2D检测结果未知".Translated();
                            resNum = resNum + 4;
                            break;
                    }
                }
                else if (i == 7)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "密封钉3D检测结果不良".Translated();
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "密封钉3D检测结果未知".Translated();
                            resNum = resNum + 4;
                            break;
                    }
                }
                else if (i == 8)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "上部R角2.5D检测结果不良".Translated();
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "上部R角2.5D检测结果未知".Translated();
                            resNum = resNum + 4;
                            break;
                    }
                }
                else if (i == 9)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "底部R角2.5D检测结果不良".Translated();
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "底部R角2.5D检测结果未知".Translated();
                            resNum = resNum + 4;
                            break;
                    }
                }
                else if (i == 10)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "柱面2.5D检测结果不良".Translated();
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "柱面2.5D检测结果未知".Translated();
                            resNum = resNum + 4;
                            break;
                    }
                }
                else if (i == 11)
                {
                    switch (res[i])
                    {
                        case 1:
                            strErr += "";
                            resNum++;
                            break;
                        case 2:
                            strErr += "柱面3D检测结果不良".Translated();
                            resNum = resNum + 2;
                            break;
                        default:
                            strErr += "柱面3D检测结果未知".Translated();
                            resNum = resNum + 4;
                            break;
                    }
                }
            }
            strErr = strErr.TrimEnd(',');
            return (ushort)resNum;
        }


        #region 结果数据上传
        /// <summary>
        /// 结果数据上传
        /// </summary>
        /// <param name="list"></param>
        private async void UpProducResultParam(List<BGearEntity> listBger)
        {
            try
            {
                if (listBger != null && listBger.Count > 0)
                {
                    foreach (BGearEntity m in listBger)
                    {
                        if (m.BarCode != "NG" && m.BarCode != "ERROR" && m.BarCode != "")
                        {
                            var AGearList = CommonMethods.db.QuerySqlList<AGearEntity>(CommonMethods.dBSQL.GetInStationTop1Sql(m.BarCode));
                            string dateStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            if (AGearList != null)
                            {
                                dateStr = AGearList.Count > 0 ? AGearList[0].TestTime.ToString() : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            }

                            string Mesage = "";
                            var (success, message) = await CommonMethods.hbgMes.ProducResultParamAsync(CommonMethods.mesConfig.ProductResultParams, CommonMethods.mesConfig.siteCode, CommonMethods.mesConfig.lineCode,
                                          CommonMethods.mesConfig.equipNum, CommonMethods.mesConfig.MaterialCode, CommonMethods.mesConfig.mesUserName, m, MesUploadType.DD, dateStr);
                            if (!success)
                            {
                                CommonMethods.AddDataMonitorLog(1, $"Code: {m.BarCode}, " + "结果数据上传失败".Translated());
                                LogHelper.Instance.WriteError($"条码: {m.BarCode}, 结果数据上传失败, {message}", "系统报错");
                            }
                            else
                            {
                                m.Flag1 = "1";
                                int a = await CommonMethods.db.UpdateSingleAsync(m, it => new BGearEntity() { Flag1 = m.Flag1 }, it => it.BarCode == m.BarCode);
                            }
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError($"结果数据上传失败, 原因: {ex}", "系统报错");
                //throw new Exception(ex.ToString());
            }

        }
        #endregion

        #region 定时补传
        /// <summary>
        /// 定时补传
        /// </summary>
        public void ReUpProducResultParam()
        {
            try
            {
                List<BGearEntity> list = CommonMethods.db.QuerySqlList<BGearEntity>(CommonMethods.dBSQL.GetOutFlag1Sql("2"));
                if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
                {
                    UpProducResultParam(list);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError($"结果数据补传失败, 原因: {ex}", "系统报错");
                //throw new Exception(ex.ToString());
            }
        }
        #endregion

        #region 判断CCD结果
        //private bool GetCcdResult(BGearEntity m)
        //{
        //    if (m.CCDNegativeTerminalWeldingZone2DInspectionResult.Contains("NG") || m.CCDNegativeTerminalWeldingZone25DInspectionResult.Contains("NG")
        //        || m.CCDCoverPlate2DInspectionResult.Contains("NG") || m.CCDCoverPlate25DInspectionResult.Contains("NG") || m.CCDTerminalPost2DInspectionResult.Contains("NG")
        //        || m.CCDTerminalPost3DInspectionResult.Contains("NG") || m.CCDSealingNail2DInspectionResult.Contains("NG") || m.CCDSealingNail3DInspectionResult.Contains("NG")
        //        || m.CCDTopFillet25DInspectionResult.Contains("NG") || m.CCDBottomFillet25DInspectionResult.Contains("NG") || m.CCDCylindricalSurface25DInspectionResult.Contains("NG")
        //        || m.CCDCylindricalSurface3DInspectionResult.Contains("NG"))
        //    { return false; }
        //    return true;
        //}
        /// <summary>
        /// ccd 外观检
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        private bool GetWGJCcdResult(BGearEntity m)
        {
            if (m.CCDResult1.Contains("NG") || m.CCDResult2.Contains("NG")
                || m.CCDResult3.Contains("NG") || m.CCDResult4.Contains("NG") || m.CCDResult5.Contains("NG")
                || m.CCDResult6.Contains("NG") || m.CCDResult7.Contains("NG") || m.CCDResult8.Contains("NG")
                || m.CCDResult9.Contains("NG") || m.CCDResult10.Contains("NG") || m.CCDResult11.Contains("NG")
                || m.CCDResult12.Contains("NG") || m.CCDResult13.Contains("NG") || m.CCDResult14.Contains("NG")
                || m.CCDResult15.Contains("NG") || m.CCDResult16.Contains("NG") || m.CCDResult17.Contains("NG")
                || m.CCDResult18.Contains("NG") || m.CCDResult19.Contains("NG") || m.CCDResult20.Contains("NG")
                || m.CCDResult21.Contains("NG") || m.CCDResult22.Contains("NG") || m.CCDResult23.Contains("NG")
                || m.CCDResult24.Contains("NG") || m.CCDResult25.Contains("NG") || m.CCDResult26.Contains("NG")
                || m.CCDResult27.Contains("NG"))
            { return false; }
            return true;
        }
        //下料不良代码 外观检
        public List<string> NGWGJcode(int[,] lstResult, int index)
        {
            List<string> NGcodelist = new List<string>();
            for (int i = 0; i < 27; i++)
            {
                if (lstResult[index, i] == 2)
                {
                    NGcodelist.Add("WGJA00" + (i + 1));
                }
            }

            return NGcodelist;
        }
        /// <summary>
        /// 判断总结果
        /// </summary>
        private (short ,string ,string) JudgmentWGJResult(int A, int[,] B, int C)
        {
            short Result = 1;
            var OK_NG = "OK";
            var NG_Type = "";
            for (int i = 0; i < 27; i++)
            {
                if (B[C, i] != 1)
                {
                    //1OK，2扫码NG，3MES反馈NG，4其他NG
                    Result = 4;
                    OK_NG = "NG";
                    NG_Type += $"外观检测NG{i + 1},";
                }
            }
            if (A == 2)
            {
                NG_Type += "无条码,";
                Result = 2;
                OK_NG = "NG";
            }

            return (Result, OK_NG, NG_Type);
        }
        #endregion

        #endregion

        #region 结构件料盘工位(数据处理)
        /// <summary>
        /// 结构件料盘工位
        /// </summary>
        /// <param name="resByte"></param>
        /// <param name="plcModel"></param>
        /// 

        private async Task MaterialStation(JYResult<byte[]> bArrays, object plcModel)
        {
            PlcGroup pf = plcModel as PlcGroup;
            var sw = new Stopwatch();
            if (bArrays.IsSuccess && bArrays.Content != null)
            {

                sw.Restart();
                #region 初始化数据
                List<DGearEntity> list = new List<DGearEntity>();//实体
                List<string> listMaterialCode = GetList<string>(1, "");//料盘码
                List<short> listRes = GetList<short>(1, 1);//默认为1，良品
                #endregion

                #region 数据解析
                byte[] bytes = bArrays.Content.ByteReverse();
                for (int i = 0; i < listMaterialCode.Count; i++)
                {
                    listMaterialCode[i] = StringLib.GetStringFromByteArrayByEncoding(bytes, i * 40, 39, System.Text.Encoding.ASCII).
                        Replace('\0', ' ').Replace('\r', ' ').Replace(" ", "").Trim();
                }
                #endregion

                for (int i = 0; i < listMaterialCode.Count; i++)
                {
                    DGearEntity m = new DGearEntity();
                    try
                    {
                        switch (pf.GroupName)
                        {
                            case "结构件料盘B":
                                m.ChannelNo = 1;
                                break;
                            case "结构件料盘D":
                                m.ChannelNo = 2;
                                break;
                        }
                        m.TestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        m.MaterialCode = listMaterialCode[i];
                        m.MaterialCodes = CommonMethods.mesConfig.MaterialCode;
                        m.EquipNum = CommonMethods.mesConfig.equipNum;
                        m.Flag = 0;
                        if (String.IsNullOrEmpty(m.MaterialCode) || m.MaterialCode.Trim() == "ERROR" || m.MaterialCode.Trim() == "NG")
                        {
                            m.MaterialCode = "NG";
                            m.Result = "NG";
                            m.Remark = "料盘码不良";
                            listRes[i] = 2;
                        }
                        else
                        {
                            m.Result = "OK";
                            m.Remark = "良品";
                            #region MES对接
                            if (CommonMethods.sysConfig.MesModeSwitching && CommonMethods.mesConfig.isConnected)
                            {
                                var (mesRes, Mesage, mesResType) = await CommonMethods.hbgMes.RawMaterialStationAsync(CommonMethods.mesConfig.MaterialInputInfo,
                                    CommonMethods.mesConfig.MaterialCode, CommonMethods.mesConfig.equipNum, m.MaterialCode);

                                if (mesRes) //调用接口成功
                                {
                                    m.Flag = 1;
                                    //本地判断OK，MES判断OK
                                    if (m.Result == "OK" && mesResType == MesResType.D)
                                    {
                                        m.Result = "OK";
                                        m.Remark = m.Remark + Mesage;
                                        listRes[i] = 1;
                                    }
                                    //本地判断OK，MES判断NG
                                    else if (m.Result == "OK" && mesResType != MesResType.D)
                                    {
                                        switch (mesResType)
                                        {
                                            case MesResType.B:
                                                m.Result = "MES NG";
                                                m.Remark = $"{Mesage}";
                                                listRes[i] = 9;
                                                break;
                                            default:
                                                m.Result = "MES NG";
                                                m.Remark = $"{Mesage}";
                                                listRes[i] = 9;
                                                break;
                                        }
                                    }
                                    //其他情况
                                    else
                                    {
                                        m.Result = " MES NG";
                                        m.Remark = Mesage;
                                        listRes[i] = 9;
                                    }
                                }
                                else
                                {
                                    m.Result = " MES NG";
                                    m.Remark = Mesage;
                                    listRes[i] = 9;
                                    if (Mesage.Contains("接口调用失败"))
                                    {
                                        listRes[i] = 10;
                                        CommonMethods.AddLog(false, $"原材料上传失败，请联系IT人员检查MES网络或服务器");
                                        LogHelper.Instance.WriteLog($"原材料上传失败，请联系IT人员检查MES网络或服务器", "SysErrorLog");
                                    }
                                }
                            }
                            #endregion
                        }
                        list.Add(m);


                    }
                    catch (Exception ex)
                    {
                        LogHelper.Instance.WriteError($"结构件料盘线程数据解析：{ex}", "系统报错");
                    }
                }
                JYResult result1 = CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue(pf.VarList[2].VarAddress, listRes.ToArray(), PLC.DataType.ArrShort);//判断结果写入PLC

                JYResult result3 = CommonMethods.plcDevices[pf.PlcNum - 1].WriteValue(pf.VarList[0].VarAddress, 0);//置位
                                                                                                                   //数据存储 -异步处理

                await SaveMaterialData(list);

                sw.Stop();
                ////输出上料数据处理耗时：
                CommonMethods.AddDataMonitorLog(0, $"结构件料盘线程共耗时：{sw.Elapsed.TotalMilliseconds}ms");
            }
        }

        /// <summary>
        /// 结构件料盘保存
        /// </summary>
        /// <param name="list"></param>
        private async Task SaveMaterialData(List<DGearEntity> list)
        {
            //数据的保存
            try
            {
                if (list != null && list.Count > 0)
                {
                    string strRes = "";
                    foreach (DGearEntity m in list)
                    {
                        if (m.MaterialCode != "NG")
                        {
                            //bool b1 = await CommonMethods.db.AddReturnBoolAsync<DGearEntity>(m);
                            //strRes = b1 ? ",本存Yes" : ",本存No";
                        }
                        else
                        {
                            strRes = ",不存储";
                        }
                        m.Remark = m.Remark + strRes;
                    }
                    //数据显示
                    CommonMethods.ShowMaterialDelegate.Invoke(list);

                }
                else
                {
                    LogHelper.Instance.WriteError($"结构件料盘数据List为空", "SysErrorLog");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError($"结构件料盘保存处理异常：{ex}", "SysErrorLog");
            }
        }

        #endregion

        #region 创建空的数组List
        public List<T> GetList<T>(int num, T data)
        {
            List<T> list = new List<T>();
            for (int i = 0; i < num; i++)
            {
                list.Add(data);
            }
            return list;

        }

        public List<MesResType> GetMesType(int Num)
        {
            List<MesResType> mesResTypes = new List<MesResType>();
            for (int i = 0; i < Num; i++)
            {
                mesResTypes.Add(MesResType.UnKnow);
            }
            return mesResTypes;
        }

        /// <summary>
        /// PLC内批量写\0
        /// </summary>
        /// <param name="Num"></param>
        /// <returns></returns>
        public string GetString_0(int Num)
        {
            string ff = "";
            for (int i = 0; i < Num; i++)
            {
                ff = ff.Insert(ff.Length, "\0");
            }
            return ff;
        }

        public string GetBarCodeNum(int Num)
        {
            string CodeNo = "";
            int CodeLenth = Num.ToString().Length;

            switch (CodeLenth)
            {
                case 1:
                    return CodeNo = $"00000{Num}";
                case 2:
                    return CodeNo = $"0000{Num}";
                case 3:
                    return CodeNo = $"000{Num}";
                case 4:
                    return CodeNo = $"00{Num}";
                case 5:
                    return CodeNo = $"0{Num}";
                default:
                    return CodeNo = $"{Num}";
            }
        }
        #endregion

        /// <summary>
        /// 检测数据是否只包含字母加数字
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public bool IsAlphaNumeric(string input)
        {
            // 使用正则表达式检查是否只包含字母和数字
            return Regex.IsMatch(input, "^[a-zA-Z0-9]+$");

        }

        #region 方法
        /// <summary>
        /// 下料数据保存本地
        /// </summary>
        /// <param name="strData"></param>
        private void BlankingDataSaveLocal(string strData)
        {
            #region 
            string savePath = string.Format(@"{0}\{1}\{2}\{3}\", @"D:\LocalData", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            bool acquiredLock = false;
            Monitor.TryEnter(FileLock, ref acquiredLock);

            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            try
            {
                if (acquiredLock)
                {
                    string strFileName = System.DateTime.Now.ToString("yyyyMMdd") + ".csv";//yyyyMMdd.csv

                    if (!File.Exists(savePath + strFileName))   //如果文件不存在，创建文件，并保存到本地
                    {
                        string strProlnfoFileHead = string.Empty;
                        foreach (var item in CommonMethods.m_DBCtrl.HeaderTextOut)
                        {
                            strProlnfoFileHead += item + ",";
                        }
                        strProlnfoFileHead = strProlnfoFileHead.TrimEnd(',');

                        strProlnfoFileHead = strProlnfoFileHead.Substring(strProlnfoFileHead.IndexOf(',') + 1);

                        StreamWriter sw = new StreamWriter(savePath + strFileName, true, Encoding.GetEncoding("GB2312"));
                        sw.WriteLine(strProlnfoFileHead);
                        sw.WriteLine(strData);

                        sw.Flush();
                        sw.Close();
                        sw.Dispose();
                    }
                    else
                    {
                        StreamWriter sw = new StreamWriter(savePath + strFileName, true, Encoding.GetEncoding("GB2312"));
                        sw.WriteLine(strData);

                        sw.Flush();
                        sw.Close();
                        sw.Dispose();
                    }
                    Monitor.Exit(FileLock);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError($"下料数据保存异常:{ex}", "SysErrorLog");
                if (acquiredLock)
                { Monitor.Exit(FileLock); }
            }
            #endregion

        }

        #endregion

        /// <summary>
        /// 电池结果辅助方法
        /// </summary>
        /// <returns></returns>
        private string GetNGReasons(int value, string reasonCode)
        {
            // 只有当值为2时才返回原因代码，否则返回空字符串
            return value == 2 ? reasonCode : string.Empty;
        }

        // 组合多个NG原因字段
        private string CombineNGReasons(params string[] reasons)
        {
            // 过滤空值并连接
            var validReasons = reasons
                .Where(r => !string.IsNullOrEmpty(r))
                .Distinct();  // 去重

            return string.Join(",", validReasons);
        }

    }
}